SHARE
TWEET

Untitled

a guest Oct 13th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // * Description:  This program will read a .txt file and print its values.
  3.  
  4.  
  5. #include <iostream>
  6. #include <fstream>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     int* array = nullptr;
  13.     int x=0, size=0, i=0;
  14.  
  15.     ifstream inFile;
  16.     inFile.open("input.txt");
  17.  
  18.     if(inFile.is_open())
  19.     {
  20.         inFile >> size;    //Reads the size of the .txt
  21.  
  22.         array = new int[size];
  23.  
  24.         cout << "\nContents of input.txt: ";
  25.         cout << "\n[";
  26.  
  27.         for(int i = 0; i < 5; i++)
  28.         {
  29.             inFile >> array[i];
  30.  
  31.             cout << array[i];
  32.             cout << ", ";
  33.         }
  34.  
  35.         cout << "]";
  36.  
  37.         inFile.close();
  38.     }
  39.  
  40.     else
  41.     {
  42.         cout << "File could not be opened!\n";
  43.     }
  44.  
  45.     return(0);
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top