0

I am keeping a large repository of strings in a character-delimited file. Currently, I am reading the strings into string variables, and then later printing them.

The problem I'm facing is how to store and print new line characters. In the file, if the string, for example, is:

"Hello this is \n\n a new line"

then the literal '\n' is printed in my program terminal when I print the string, however I would like to print new lines.

Is this a matter of processing the strings character by character, or is there a proper way to read the strings into the string variables that will allow this to work?

jimroot
  • 59
  • 1
  • 7
  • 1
    I think you'll need to parse the string, so as to discard the delimiting `" ` at the start and end, and converting the embedded `\n ` two character sequence into a newline character. There may be other sequences you'll need to convert, for example possibly `\\ ` and `\" `. – Eljay Apr 19 '19 at 19:19
  • See answers in https://stackoverflow.com/q/2896600/277176 for how to replace substrings. – Yakov Galka Apr 19 '19 at 19:27
  • `std::quoted` can handle the `"` quotes for you, but unfortunately breaks the newlines (need double escapes then). So you're best of just writing a input / conversion function yourself. – Daniel Jour Apr 19 '19 at 19:37

0 Answers0