Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // * Description: This program will read a .txt file and print its values.
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- int* array = nullptr;
- int x=0, size=0, i=0;
- ifstream inFile;
- inFile.open("input.txt");
- if(inFile.is_open())
- {
- inFile >> size; //Reads the size of the .txt
- array = new int[size];
- cout << "\nContents of input.txt: ";
- cout << "\n[";
- for(int i = 0; i < 5; i++)
- {
- inFile >> array[i];
- cout << array[i];
- cout << ", ";
- }
- cout << "]";
- inFile.close();
- }
- else
- {
- cout << "File could not be opened!\n";
- }
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement