
Untitled
By: a guest on
May 1st, 2012 | syntax:
None | size: 0.57 KB | hits: 15 | expires: Never
= with strings in C
string s = "hi";
s += " " + "there!";
error: invalid operands of types ‘const char [2]’ and ‘const char [6]’ to binary ‘operator+’
std::string("foo") + "bar"
s += string(" ") + "there!";
s += " " "there!";
632 $ g++ foo.C
foo.C: In function ‘int main()’:
foo.C:5:16: error: invalid operands of types ‘const char [2]’ and ‘const char [7]’ to binary ‘operator+’
636 $ cat foo.C
#include <string>
using std::string;
int main(void){
string s = "hi";
s += string(" ") + string("there!");
return 0;
}