Advertisement
Guest User

Untitled

a guest
Aug 6th, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. /*
  2.  * main.cpp
  3.  *
  4.  *  Created on: Aug 6, 2011
  5.  *      Author: romin
  6.  */
  7.  
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.     //create object of type ifstream and open "data.txt"
  14.     ifstream ifs("data.txt");
  15.  
  16.     //check to see if "data.txt" was successfully opened
  17.     if(!ifs)
  18.     {
  19.         cerr << "Could not open the file.\n";
  20.         exit(1);
  21.     }
  22.  
  23.     //read data.txt, a list of integers
  24.     int x=0;
  25.     while(ifs >> x)
  26.     {
  27.         cout << x << " ";
  28.     }
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement