Bytes

Given this Windows text file open in hexedit. I'm using Visual Studio.

Scenario 1:

Open using std::ifstream jconfig("jconfig.cfg");

Using ls -l it has a file size of 17 bytes.

On code snippet:

But when loading content into array, the array has size of 15 bytes

Then examining cfg buffer shows:

So two 0D are lost

And then using std::getline and checking one line, shows:

Notice instead now the NULL terminator

Scenario 2:

Open file is binary.

This snippet gives 17:

Then this snippet shows exactly the content:

Examining buf shows:

Content is intact

And then using std::getline examining one line of read gives:

Full code below:

Here is another Unix file, contents in hexedit. Doing ls -l shows it has 47 bytes.

... all read seems 47 fine. Be careful with notepad?

Last updated

Was this helpful?