intergers.txt 4 7 2 5 3 #include #include using namespace std; int main() { int num[100],i=-1; // variable declaration to read the integer data char tx;//variable declared ifstream myFile; // input file declaration myFile.open("numbers.txt"); // Syntax for open the file and read integer.txt while (!(myFile.eof())){ myFile >> num[i]; i++; // read the integer content from the file //myFile>>tx; // read the comma } num[i] = num[i+1]; // Delete the last garbage value cout<<"The elements in the array are "; for(int j=0;j
can someone check why my code is not working?
intergers.txt
4
7
2
5
3
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int num[100],i=-1; // variable declaration to read the integer data
char tx;//variable declared
ifstream myFile; // input file declaration
myFile.open("numbers.txt"); // Syntax for open the file and read integer.txt
while (!(myFile.eof())){
myFile >> num[i];
i++;
// read the integer content from the file
//myFile>>tx; // read the comma
}
num[i] = num[i+1]; // Delete the last garbage value
cout<<"The elements in the array are ";
for(int j=0;j<i;j++){ // Loop to run for all the elements in the array
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 1 images









