Hello, I am trying to read a file containing two lines of text, like such:
UserName
HOST\Owner
The text was written to a text file named "CompNames.txt" by a batch file, and it appears just as above. When I attempt to read it using ifstream, it prints the text of the second line of the file to another file names "op.txt" (as expected); however each character is separated by a box, which appears to signify that there were characters that the output could not read, I can't copy and paste this, but it most closely resembles:
☐H☐O☐S☐T☐O☐w☐n☐e☐r☐☐☐
☐::cname
I searched forums for a while and found numerous occurrences of this happening at the end of a line or file but never in the midst of one. Here is a snippet of my code:
By the looks of it, your file is stored using UTF-16 encoding, but you're reading it using plain (non-converting) std::ifstream
Since you're using Visual C++, you can either use standard utf16 conversion functions from the header <codecvt> or use Microsoft's _O_U16TEXT file mode. Either way, you'll be reading into a wide characters string. Or perhaps it would be easier to save the file in a single-byte encoding.