I'm having a wee problem with the get method, here is my code :
ifstream infile;
char x;
infile.open("te mp.txt");
if( !infile.good() )
{
cout << "Error opening file" << endl;
system("PAUSE") ;
exit(1);
}
while( !infile.eof() )
{
infile.get(x); //reads in characters
x=toupper(x); //converts characters to upper case
cout << x << '\t';
}
The file temp.txt contains one word - "beer". However when I run the above
code I get BEERR (notice the two R's at the end). What gives ?
Thanks for any help.
ifstream infile;
char x;
infile.open("te mp.txt");
if( !infile.good() )
{
cout << "Error opening file" << endl;
system("PAUSE") ;
exit(1);
}
while( !infile.eof() )
{
infile.get(x); //reads in characters
x=toupper(x); //converts characters to upper case
cout << x << '\t';
}
The file temp.txt contains one word - "beer". However when I run the above
code I get BEERR (notice the two R's at the end). What gives ?
Thanks for any help.
Comment