Hello, My code is not working it is not displaying he numbers of the text file to the array. Please help show output Output needs to be: The numbers in the array are 4, 7, 2, 5, 3 and must use: while (!(myFile.eof())){ myFile >> num[i]; i++; interger.txt intergers.txt 4 7 2 5 3 #include #include using namespace std; int main() { int num[100],i=0; // variable declaration to read the integer data //char tx;//variable declared ifstream myFile; // input file declaration myFile.open("integer.txt"); // Syntax for open the file and read integer.txt //while (myFile >> num[++i]) while (!(myFile.eof())){ myFile >> num[i]; i++; } cout<<"The numbers in the array are "; for(int j=0;j
Hello, My code is not working it is not displaying he numbers of the text file to the array. Please help show output
Output needs to be:
The numbers in the array are 4, 7, 2, 5, 3
and must use:
while (!(myFile.eof())){
myFile >> num[i];
i++;
interger.txt
intergers.txt
4
7
2
5
3
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int num[100],i=0; // variable declaration to read the integer data
//char tx;//variable declared
ifstream myFile; // input file declaration
myFile.open("integer.txt"); // Syntax for open the file and read integer.txt
//while (myFile >> num[++i])
while (!(myFile.eof())){
myFile >> num[i];
i++;
}
cout<<"The numbers in the array are ";
for(int j=0;j<i;j++){ // Loop to run for all the elements in the array
cout << "The score of array "<<[j] << endl;
if(j==i-1)
cout<<num[j]<<endl; // print element with new line
else
cout<<num[j]<<","; // print the array
}
myFile.close(); //close the file
return 0;
}

Step by step
Solved in 2 steps with 2 images









