如果我想用如下一行构造一个 std::string:
If I want to construct a std::string with a line like:
std::string my_string("a b");
如果我想在结果字符串中包含三个字符(a、null、b),我只得到一个.正确的语法是什么?
Where i want to have three characters in the resulting string (a, null, b), I only get one. What is the proper syntax?
我们已经能够创建文字std::string
#include <iostream>
#include <string>
int main()
{
using namespace std::string_literals;
std::string s = "pl- -op"s; // <- Notice the "s" at the end
// This is a std::string literal not
// a C-String literal.
std::cout << s << "
";
}
问题是采用 const char*
的 std::string
构造函数假定输入是 C 字符串.C 字符串被