So I've been learning about steams and have been experimenting on my own. I was attempting to write a simple program to read the first line of a file only. But I've noticed an issue in Visual Studio 2019. Below is the code snippet.
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::ifstream in("Test.txt", std::ios::binary);
if (in)
{
std::string store;
std::getline(in, store, '\n');
std::cout << store;
}
return 0;
}
The test.txt file reads:
This
Is
A
Test
In VS19 the output to the console is just " his". In VSCode the output is "This" as it should be. Am I doing anything wrong in VS19 as far as possible configuration? Is it a bug? It was driving me crazy until I tried a different IDE, can't figure out why it would be doing that. Note: It isn't ignoring the first character of the string, it is replacing it with whitespace.
Hex of Test.txt for VS2019
00000000 54 68 69 73 0D 0A 49 73 0D 0A 41 0D 0A 54 65 73
00000010 74
And VSCode
00000000: 54 68 69 73 0A 49 73 0A 41 0A 54 65 73 74