临时遇到的问题,突然就蒙了。记一下:
# include <stdio.h>
# include <string>
# include <iostream>
using namespace std;
int main()
{
char a[] = "abc ";
string str = a;
cout<< str<< " "<<str.size()<<endl;
sscanf(a,"%s",a);
string str1 = a;
cout<< str1<< "; "<<str1.size()<<endl;
string str2 = a;
str2.erase(str2.find_last_not_of(" ") + 1);
cout<< str2<< "; "<<str2.size()<<endl;
return 0;
}
结果:
abc 12
abc; 3
abc; 3