static_castを使えばできる
1 | y = static_cast < double >(x); |
型変換した後する前と変換後で型を調べる。
実行結果
1 2 | int double |
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <iostream> #include <typeinfo> int main() { int x; double y; x = 1; y = static_cast < double >(x); std::cout << typeid (x).name() << std::endl; std::cout << typeid ( static_cast < double >(x)).name() << std::endl; } |
コメント