Jump to content

Recommended Posts

#include <iostream>

#include <iomanip>

#include <string>

#include <fstream>

 

using namespace std;

 

int main(){

    string inputFile;

    ifstream inFile;

    int count = 0;          // keep track of number of integers read

    int numbers[19];        // array to store our integers

 

    cout << "Enter the name of the data file now: " << endl;

    cin >> inputFile;

        inFile.open(inputFile.c_str());

       

        while(!inFile){

                cout << "==> Error opening file: " << inputFile << endl;

                cout << "==> Try Again..." << endl;

               

                inFile.clear();

               

                cout << fixed << "Enter the name of the data file now: ";

                cin >> inputFile;

                cout << inputFile << endl << endl << endl;

       

                inFile.open(inputFile.c_str());

        }

        while(count <= 19 && inFile >> numbers[count]){

                cout << numbers[count] << endl;

                count++;

        }

 

    system("pause");

    return 0;

}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.