On 16 Dec 2006 16:54:40 +1100, Gary Wessle <> wrote in
comp.lang.c++:
> Hi
>
> any idea why I am getting something like
>
>
> main.cpp:177: error: invalid operands of types ‘const char [11]’ and ‘const char [8]’ to binary ‘operator+’
>
>
> when trying to compile something like
>
> int main(int argc, char* argv[])
> {
> string a = ".........." + ".......";
> cout << a << endl;
> }
>
> how can I solve this, I have few lines and use + to concatenate them
> together.
In addition to Gianni's answer, there is one thing you can do that
only works for string literals in source code, namely leave out the
'+'.
The code:
string a = "abc" "def" "ghi";
....produces exactly the same result as:
string a = "abcdefghi";
And so does this:
string a = "abc"
"def"
"ghi";
String literals that are separated by nothing but white space are
concatenated by the preprocessor when compiling.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html