problem with file.get() function

for some reason "file.get () >> char ran;" isn't working.
the getline(file, string ran) works fine, but it wont work for a single character.

char grid [7][6];
string ran;

int i = 0, j = 1;
while(!file.eof())
{
getline(file, ran);
cout << ran << endl;
// for(i = 0; i < 7; i++)
// {
// file.get() >> grid [i][j];
// cout << " " << grid [i][j] << " ";
// }
// cout << endl;
// j++;
}

this shows both the file.get() way and getline() way. please help. i cant find it anywhere.

its important to note: it will still do the cout part, just not the right characters.
file.get () >> char ran;

file.get() returns an int. The >> operation applied to an int in this context makes no sense.

Here is something that does make sense.
file >> grid [i][j];
Last edited on
hmm, is file.get() returning the ascii value of the character?
http://www.cplusplus.com/reference/iostream/istream/get/

int get();
Extracts a character from the stream and returns its value (casted to an integer).
Topic archived. No new replies allowed.