0

I am writing a program that needs to read in a list of 11,000 numbers from a text file and then output them to the console. However, whenever I run my code, I have been able to pinpoint that it only prints the last 299 numbers. Here is my code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
double dataVector[11000]; //text file has 11,000 elements
string userfile; //name of file selected by user

//prompt user for file to be opened
cout << "Enter the name of the file you would like to read :: ";
cin >> userfile;

ifstream ifs(userfile); //open file
if (!ifs) // return error message if file cannot be opened
{
    cerr << "Error: could not find the specified file" << endl;
    return 1;
}

for (int i = 0; i < 11000; i++)
{
    if (ifs >> dataVector[i]) //read in array 
        cout << dataVector[i] << endl;
    else //if element cannot be read, return error
    {
        cout << "Failed to read." << endl;
        break;
    }
}

ifs.close(); //closes the file
system("pause");

return 0;
}

Is there something that I'm missing that's causing this issue? My code is not returning any compiler errors, no errors from my checks, and my text file IS in the right location.

littmuslozenge
  • 3
  • 1
  • 2
  • 5
  • 4
    What you're probably missing is the fact that your terminal program has only a 300-line scrollback buffer. I think you'll find it's outputting the lot but you're only able to scroll back so far. Run the program capturing standard output (eg, `prog >prog.out`) then look at the output file. – paxdiablo Mar 12 '17 at 04:28
  • @paxdiablo Ah, that makes a lot of sense. Thank you! – littmuslozenge Mar 12 '17 at 04:42

0 Answers0