c++ char 转 int string 转int

c++有编码问题,char无法直接转int,转换方法很多,下面介绍一个比较简单明了的:

char x='8';
int y=x-'0';

string 转 int

	string a = "20210629";
	string s = a.substr(0, 4);
	int y = atoi(s.c_str());
	cout << y << endl;//2021
posted @ 2021-06-18 16:33  callcall  阅读(638)  评论(0编辑  收藏  举报