tags:

views:

78

answers:

5

Hi, When I did the practice below to erase my pointer member and assign new value to it.

(*pMyPointer).member.erase();
(*pMyPointer).member.assign("Hello"); // Successfully

Than I tried more...

(*pMyPointer).member.erase();
(*pMyPointer).member.assign("Long Multi Lines Format String"); // How to?

If the long multi lines string can't quote by double quoter, how to handle it. Thank you.

+2  A: 

Line breaks in string literals are '\n':

"This is a string literal\nwith a line break in it."
sbi
+2  A: 

I'm pretty sure that this is a duplicate of this question see the link for the solution.

radman
This should be a comment.
sbi
pity i don't have the rep to add a comment :P
radman
+2  A: 

I assume you mean passing a very long string constant as a parameter, in which case C++ does the string-merging for you: printf("hello, " "world"); is the same thing as printf("hello, world");

Thus:

(*pMyPointer).member.assign("Long Multi Lines Format String "
       "and here's more to the string "
       "and here's more to the string "
       "and here's more to the string "
       "and here's more to the string "
       "and here's more to the string ");
egrunin
Argh! Beat me to it!
Daniel
+3  A: 

I really have no clue what you are trying to ask. Maybe this:

(*pMyPointer).member.assign("Long Multi Lines Format String"
                            "more lines that will be"
                            "concatenated by the compiler");

Or did you mean line breaks like this:

(*pMyPointer).member.assign("Long Multi Lines Format String\n"
                            "more lines that will be\n"
                            "concatenated by the compiler");
Johann Gerell
+1: I'm guessing your guess is a good guess.
Binary Worrier
@Binary: I guess so.
Johann Gerell
+1  A: 

I think the question is is how to create a multi-line string.

You can easily do it with:

(*pMyPointer).member.assign(
    "Long Multi Lines Format String" \
    "Long Multi Lines Format String" \
    "Long Multi Lines Format String"
 );

You'll have to add a \n to the string if you want to return. Otherwise it's going to stay on the same line.

Daniel