本文主要是介绍C++去掉string , char[] 右边的空格,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
临时遇到的问题,突然就蒙了。记一下:
# 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
这篇关于C++去掉string , char[] 右边的空格的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!