computer beeps at me for this, what am i doing wrong ?

Started by
1 comment, last by vaneger 14 years, 10 months ago

void main()
{
	int i = 0;
	char data = 'o';
	char * ptr_to_data = &data;
	ifstream file ("example.txt",ios::in|ios::binary);

	while( !file.eof() )
		{
			i++;
			file.read(ptr_to_data,1);
			cout<<data<<endl;
		}
        cout<<i<<endl;
        file.close();
        return;
}

This is trivial code to figure out how many bytes a file is, and when I execute it, it runs fine as far as I can tell, but the computer beeps at me and I'm not sure why.
Advertisement
Because you're outputting the file data as well, and some of those bytes (the ones with a value of 7) are interpreted by the console as beeps rather than as printable symbols.
neat, I didn't know that.

This topic is closed to new replies.

Advertisement