Hi, everyone,
I got a problem in the C++ programming when reading data file. The codes are attached below. In the for loop, the data file can only be opened once. When j=2, it does not open the file. I don't understand why. Is there anyone can give me a hand? I've been struggling for a while.
Thanks a lot!
SwingXH
#include<iostream>
#include<stdio.h>
#include<fstream>
#include<stdlib.h>
#include<cmath>
#include<string>
#include <windows.h>
#include <winuser.h>
#include <cstdlib>
using namespace std;
double X;
int count2, count1;
int main()
{
ifstream in1;
ifstream in2;
int j;
for (j=1;j<3;j++)
{
in1.open("x.rez");
count2=0;
while (in1>>X)
{
count2=count2+1; cout<<count2<<endl;
cout<<X<<endl;
}
in1.close();
cout<<count2<<count1<<endl;
}
return 0;
}
I got a problem in the C++ programming when reading data file. The codes are attached below. In the for loop, the data file can only be opened once. When j=2, it does not open the file. I don't understand why. Is there anyone can give me a hand? I've been struggling for a while.
Thanks a lot!
SwingXH
#include<iostream>
#include<stdio.h>
#include<fstream>
#include<stdlib.h>
#include<cmath>
#include<string>
#include <windows.h>
#include <winuser.h>
#include <cstdlib>
using namespace std;
double X;
int count2, count1;
int main()
{
ifstream in1;
ifstream in2;
int j;
for (j=1;j<3;j++)
{
in1.open("x.rez");
count2=0;
while (in1>>X)
{
count2=count2+1; cout<<count2<<endl;
cout<<X<<endl;
}
in1.close();
cout<<count2<<count1<<endl;
}
return 0;
}