Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如,我想访问cout操作数
cout
cout << "Hello";
在这里,我想访问字符串“Hello”,它是运算符的操作数<<并想要修改。
<<
我可以这样做吗?如果有怎么办?
之后cout << "Hello",您将无法访问"Hello"。您必须事先访问它。
cout << "Hello"
"Hello"
您不能"Hello"在运行时修改字符串文字,因为它的类型是const char*. 您必须创建一个字符串并修改该字符串:
const char*
std::string hello = "Hello"; hello[0] = 'B'; std::cout << hello; // prints "Bello"