Heres는 내 코드바이너리 파일을 두 번 이상 사용할 수 없습니까?
#include <iostream>
#include <fstream>
using namespace std;
struct a
{
int x;
int b;
};
int main()
{
ifstream rfile("test.bin", ios::binary);
a ob;
//Reading from the file for the first time works fine.
rfile.read((char*)&ob, sizeof(ob));
while (rfile)
{
cout<<ob.x<<endl;
rfile.read((char*)&ob, sizeof(ob));
}
rfile.seekg(0, ios::beg);
cout<<"G:"<<rfile.tellg()<<endl; //Outputs -1
rfile.read((char*)&ob, sizeof(ob));
while (rfile)
{
cout<<ob.x<<endl;
rfile.read((char*)&ob, sizeof(ob));
}
return 0;
}
출력은 제 1 루프 작동 2 루프 dosent 작업 에서처럼
3
1
G:-1
되기 때문에 포인터의 위치가 -1에도 seekg 사용 후(). 왜 이런 일이 일어나는 걸까요?