I’m creating a program that reads in a text file. Each seperate line in the file represents a new string within the program; each string would be saved to the same vector. Specifically, I would save the first character of every new line to a std::vector<char*>
. My goal was to: (-) read the full text to the heap, (-) then push_back to the vector a char pointer for each new string (thus being: for each new character after a newline), (-) and then replace all the newlines with {$content}
‘s, so that whenever I sent one of the strings to std::cout
, it would automatically not print everything that came after, which counted as the next strings, since the system would think the string has ended.
So I coded that (using std::fstream
and std::fstream::read(char*, size_t)
) and noticed there was a problem: the strings came out weird to the console. When I opened the text file with a hex editor, I saw the problem was that newline characters were represented with u000Du000A
, instead of …(whatever the number is for 'n'
).
I tried saving the file in ANSI mode (which I am told is supposed to save files with ASCII encoding), it still saved newlines as u000Du000A
.
How can I either adjust the code or the file to make it work the way I want, without saving each line as a seperate std::string
?
Source: Windows Questions C++