- 字符串转整形“1024”->1024
int cnt=0;
while(s[i]>='0'&&s[i]<='9')
cnt=cnt*10+s[i++]-'0';
2.四舍五入
cout<<int((((G1-maxs-mins)*1.0/cnt)+G2*1.0)/2.0+0.5)<<endl;
3.c_str()的用法
C中没有string,所以函数c_str()就是将C++的string转化为C的字符串数组,c_str()生成一个const char *指针,指向字符串的首地址。
char *p=s[10];
string a="welcome";
strcpy(p,a.c_str());
cout<<p;
结果为"welcome".
4.字符串转整型
#include<stdlib.h>
char str[]= "1024";
a = atoi(str);
5.字符串转浮点型
#include<stdlib.h>
a=atof(str);