I'm trying to read a file called numbers.txt and insert the integers into an array. My code outputs only the last integer in the file.
//numbers.txt
1
10
7
23
9
3
12
5
2
32
6
42
My code:
int main(){
ifstream myReadFile;
myReadFile.open("/Users/simanshrestha/Dev/PriorityQueue/PriorityQueue/numbers.txt");
char output[100];
int count = 0;
if (myReadFile.is_open()) {
while (!myReadFile.eof()) {
myReadFile >> output;
//cout<< output << endl;
count++;
}
for(int i=0;i<count;i++)
{
cout << output[i];
}
cout<<endl;
}
cout << "Number of lines: " << count<< endl;
myReadFile.close();
return 0;
}
See Question&Answers more detail:os