Tuesday 15 January 2013

C++ const std::string assignment error if the right handside contains concatenation on string literals -


I am new to C ++, I have encountered this inequality with const std :: string assignment

This works fine: const std :: string hello = "hello"; Const std :: string message = hello + "world";

This gives the compiler error: const std :: string message = "Hello" + "world";

I do not

nobody is < P> Thanks

operator + which takes two points type const char * and returns a new array of letters in which they point to

You can:

  std :: string message = std :: string ("hello") + "world";   

or even:

  std :: string message = "hello" + std :: string ("world");    

No comments:

Post a Comment