1. STL中的 string 类型支持类似java中的直接进行字符串相加,但是不支持相减
#include <iostream> #include <string> using namespace std; int main() { string str = "Hello World"; str += " I am comming!"; cout << str << endl; //只能+=,不能-= int a = 123456; str = to_string(a); //c++11引入的,编译时需要加上-std=c++11 cout << a << endl; printf("str=%s ", str.c_str()); //string和char*转换 return 0; } $ g++ std_string.cpp -o pp -std=c++11 $ ./pp Hello World I am comming! 123456 123456
【C++ STL String】常用操作: https://www.jianshu.com/p/90584f4404d2
std:string: https://blog.csdn.net/L_insting/article/details/110149869