casts/casts1-compilable.cc - The compilable parts of the program from above. | Lecture 3 - slide 6 : 27 Program 2 |
// The compilable parts of the previous program. #include <iostream> #include <string> int main(){ // Static casting int to double: int k{3}; double f{static_cast<double>(k)}; std::cout << f <<std::endl; // 3 // Static casting double to int: double d{123.456}; int j{static_cast<int>(d)}; // j initialized to 123 std::cout << j <<std::endl; // 123 }