I am reading the content of a file character by character:
The file has:
000001111100000
When I use this code to read
int content;// converting to char will result in proper output.
std::ifstream fin;
fin.open("zero_one");
fin>>content;
while (!fin.eof())
{
std::cout<<content;
fin>>content;
}
fin.close();
I get the output as: 1111100000 (the leading zeros are not present) but the trailing zeros are present.
The concern is: as I am using >> operator to read then, why don't I get the leading zeros in output whereas as I get the trailing zeros in output.
Also, If I convert the int to char for content variable then the output is same as the content of the file. Why is this so? As far as I know, the only difference between the char and int is the size in bytes of the variable.