字符串与数字之间的转换
目录
方法一(利用的stringstream,可以是浮点数)
数字to字符串
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
double x;
string str;
stringstream ss;
cin >> x;
ss << x;
ss >> str;
cout << str;
return 0;
}
字符串to数字
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
double x;
string str;
stringstream ss;
cin >> str;
ss << str;
ss >> x;
cout << x;
return 0;
}