字符串与数字的转换

字符串转换
#include <iostream>
#include<sstream>
#include<string>
using namespace std;

int main()
{
	char p[] = "12344";
	string m = "12344";
	int q[] = { 1,2,3 };
	bool w1 = (p[1] == m[1]);
	bool w2 = (p[1] == q[1]);
	cout << w1 << " " << w2 << endl;
	cout << (p[1]-'\0') * 10 << endl;
	cout << m[1] * 10 << endl;
	double a = 123.32;
	string s = to_string(a);//数转化为字符串
	cout << s[1] * 10 << endl;
	cout << s << endl;
	cout << stod(s)*10 << endl;//字符串转换为double
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43425693/article/details/89926498