sizeof作用于一个string,并不是string中字符串呃长度,而是string这个类的大小。
std::string s = {};
std::cout << "sizeof(s):" << sizeof(s) << "," << s << std::endl;
s = "hello world!";
std::cout << "sizeof(s):" << sizeof(s) << "," << s << std::endl;
sizeof(s):32,
sizeof(s):32,hello world!
对于string view
std::string_view sv = s;
std::cout << "sizeof(sv):" << sizeof(sv) << "," << sv << std::endl;
sizeof(sv):16,hello world!