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
  • 8,789
  • 29
  • 95
  • 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,135
  • 10
  • 69
  • 120
2

Line breaks in string literals are '\n':

"This is a string literal\nwith a line break in it."
sbi
  • 212,637
  • 45
  • 247
  • 432
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,038
  • 8
  • 48
  • 92
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
  • 880
  • 6
  • 5