我有问题std::string..
问题是'\0'被识别为字符串的结尾,就像在类似C的字符串中一样.
例如以下代码:
#include <iostream>
#include <string>
int main ()
{
std::string s ("String!\0 This is a string too!");
std::cout << s.length(); // same result as with s.size()
std::cout << std::endl << s;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
7
String!
Run Code Online (Sandbox Code Playgroud)
这里有什么问题?不应该像任何其他角色一样std::string对待'\0'?