0

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.

Nano HE
  • 9,109
  • 31
  • 97
  • 137

4 Answers4

3

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
  • 24,991
  • 10
  • 72
  • 122
2

Line breaks in string literals are '\n':

"This is a string literal\nwith a line break in it."
sbi
  • 219,715
  • 46
  • 258
  • 445
2

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
  • 24,650
  • 8
  • 50
  • 93
1

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
  • 878
  • 6
  • 5