不废话了
代码在此:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int a;
cin >> a;
string str = to_string(a);
if (str[0] == '-')
cout << "这是一个" << str.length() - 1 << "位的负数" << endl;
else
cout << "这是一个" << str.length() << "位的正数" << endl;
}
测试平台:vs2019
to_string()函数
头文件: #include <string>
功 能: 将括号内的 数字 转化为 字符串
其他资料:
string 与 int 互相转换
其他博友还有什么更好的方法欢迎留言与我讨论!