一。整型到字符串
给定的一个整型数,如何转化成字符串?
1. int i=255;
char a[N];
sprintf(a,"%d",i);
ok
2.
string str= itos(i);
string itoa(int i)
{
string tmp="";
do
{
char ch = i%10 + '0';
tmp.insert(0,&ch);
}while( (i=i/10)!=0 )
return tmp;
}
ok
当然把最前面的0值滤掉
二。字符串到整型
库函数 atoi atof atol
如果有一定的格式如:"10:28:25",把对应的时间对出来,h,m,s。
string str="10:28:25";
sscanf("str.c_str(),"%d:%d:%d",&h,&m,&s);
欢迎补充