Hi,
I am trying to open a file called new with say any variable numbers of integers say 3 9 4 1 4 or 2 5 1 4, I am able to read in the data, but since my size is fixed to 11 by the #define size 11 macro, I read 3 9 4 1 4 0 0 0 0 0 0 followed by extra zeros which I don't want to be read, when I just am trying to get
the exact 3 9 4 1 4 to be read, or 2 5 1 4 instead of 2 5 1 4 0 0 0 0 0 0 0. If anyone can help that would be great, I've attached my code. Thanks for any help.
Code:#include <cstdlib> #include <iostream> #include <fstream> #define size 11 using namespace std; int main(int argc, char *argv[]) { ifstream infile; int i, j, total; int *num; num = new int[size]; infile.open("new.txt"); while (!infile.eof() ) { for (i=1; i <= size ; i++){ infile >> num[i]; } } infile.close(); for (i = 1; i <= size; i++){ cout << num[i] << " "; } delete [] num; system("PAUSE"); return EXIT_SUCCESS; }



LinkBack URL
About LinkBacks



):