【发布时间】:2017-09-12 19:03:46
【问题描述】:
char stringToAdd[4097] = "";
// some manipulations on stringToAdd to add some value to it.
if(stringToAdd[0] != '\0') {
response = MethodCalledHere("Some Random text");
}
MethodCalledHere(const String& inputParameter) {
// some method definition here.
}
我必须将 stringToAdd 添加到“一些随机文本”中。类似的东西 -
response = MethodCalledHere("Some Random text" + stringToAdd);
但这给了我一个错误 '+' 不能添加两个指针。
有什么建议吗?
【问题讨论】:
-
可以使用
std::stringstream,或者将第一个字符串封装在构造函数中... -
或者使用
std::string文字 -
C++14 酷猫使用
""s + "Some Random text" + stringToAdd;注意内置的用户定义文字。与 Java 中的 + 可憎不同,这不是杂牌。 -
@Charles - 你到底是怎么建议的?
-
@Bathsheba - 这似乎修复了错误,但我没有得到这个概念。如果你能解释一下。
标签: c++ arrays string pointers character