string类型转int类型

String类型转int类型

C语言形式:

int main()
{
	
	string str = "123";
	int i = atoi(str.c_str());
	cout << i << endl;
	
	system("pause");	
	return 0;
}	

C++形式:

int main()
{
	
	string str = "123";
	int i = stoi(str);
	cout << i << endl;
	
	system("pause");	
	return 0;
}	

转long类型:stol()

转float类型:stof()

转double类型:stod()

发布了36 篇原创文章 · 获赞 6 · 访问量 2037

猜你喜欢

转载自blog.csdn.net/the_sea1/article/details/102702308