在C++中,可以使用`typeid`运算符来查看数据类型。
使用`typeid`运算符需要包含头文件``。
以下是使用`typeid`运算符查看数据类型的示例代码:
```cpp #include #include
int main() { int num = 10; double pi = 3.1415; std::string str = "Hello";
std::cout << "num 的数据类型是:" << typeid(num).name() << std::endl; std::cout << "pi 的数据类型是:" << typeid(pi).name() << std::endl; std::cout << "str 的数据类型是:" << typeid(str).name() << std::endl;
return 0; } |