-
std::string length() and size() member functions.
As per the documentation, these are just synonyms. -
Error: invalid operands of types ‘const char [35]’ and ‘const char [2]’ to binary ‘operator+’
std::string str = "Hello " + "world"; // bad!
std::string str = std::string("Hello ") + "there " + "world"; // ok
- char* 与 string https://www.cnblogs.com/devilmaycry812839668/p/6353807.html
const char *st = "hello";
// 赋值转换
string st1 = st;
// 构造转换
string s1(st, st + strlen(st));
// string转char *
string st = "My test";
//char *st1 = st; // 错误类型不同
//char *st1 = st.c_str(); // 错误类型不同, const char* c_str() const; st对象被析构时,其内容将丢失!
char *st1 = const_cast<char *>(st.c_str()) ;