【发布时间】:2014-07-19 19:04:16
【问题描述】:
我知道我可以使用stringstream,但我希望有一种更简单的方法来编写"hello" + a_std_string_object。
【问题讨论】:
-
"hello" + a_std_string_object应该按书面方式工作。你有问题吗? -
a_std_string_object.insert(0, "hello");
我知道我可以使用stringstream,但我希望有一种更简单的方法来编写"hello" + a_std_string_object。
【问题讨论】:
"hello" + a_std_string_object 应该按书面方式工作。你有问题吗?
a_std_string_object.insert(0, "hello");
如果您有旧的/损坏的编译器,则可能需要
string("hello") + std_string_object
但在现代编译器中,自然代码
"hello" + std_string_object
应该可以。
【讨论】:
"hello" + std_string_object 至少从 C++98 开始就有效。也许您正在考虑使用 const char * 添加字符串文字。