While loop that runs until reading in an int fails

Hi! I'm writing a program that opens a file that contains a list of ints and ends with a non-int (i.e., "1 2 1 1 R_81UvYeXatfu4VoN"). I want to have a while loop that reads in the ints one at a time and couts them and ends when the int tries to read in the non-int and fails. Below is the code I thought would work, but is not (instead of couting "1211", it couts "21".Thanks for your help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{  
  string filename;
  ifstream ourfile;
  cout << "What file do you want to use?  ";
  cin >> filename;
  ourfile.open(filename.c_str());

  int number = 0;
  while (ourfile>>number)
  {
     ourfile>> number;
     cout << number;
  }

Remove line 12;
Thanks!
Topic archived. No new replies allowed.