I have a file of type: data, and I want to read that file the same way I see the contents of the file with the command
od -D filename on Linux
In other words, the contents of the file are:
0000000 000002 000000 000002 000000 000002 000000 000002 000000
0000020 000004 000000 000004 000000 000004 000000 000004 000000
0000040 000006 000000 000006 000000 000006 000000 000006 000000
0000060
But with the od -D filename command on Linux, I see:
0000000 2 2 2 2
0000020 4 4 4 4
0000040 6 6 6 6
0000060
I want to read this file in C ++ so that I don't have to manipulate the data, but simply retrieve 222244446666
In the code below I am reading in a way that works, but if the file contains values = 0, I will not be able to rescue them in the reading.
ifstream file2 (file, ios :: in);
char ch;
if (file2.is_open ())
{
while (! file2.eof ())
{
file2.get (ch);
double num = ch;
//if (num != 0) {
cout << num << endl;
//}
}
}
file2.close ();
When I read this way it looks like:
2
0
0
0
2
0
0
0
2
0
0
0
2
0
0
0
4
0
0
0
4
0
0
0
4
0
0
0
4
0
0
0
6
0
0
0
6
0
0
0
6
0
0
0
6
0
0
0
0
I want to know how I can read this file so that it only takes the real values, that is, 222244446666, but if it contains 0 values I also need to get them. Example: 000022224444 (That is why I commented if num != 0, this doesn't work for all cases)
That is, I need to eliminate these zeros as the od -D filename command does