내 파일을 거치기위한 반복기를 만들려고합니다. 내 파일은 바이너리이며 내부에 int 값을 가지고 있으므로 내 관점에서는 그렇게 작동해야합니다. 하지만 오류가 나타납니다 "데이터 멤버의 잘못된 사용"IntFile :: file ' "그래서 내가 코드를 어디에 오류가 나타납니다. 어떻게 관리 할 수 있습니까? 내가 오류를 받고 있어요cstdio와 함께 작동하는 사용자 정의 iterator 구조체 만들기
#include <iostream>
#include <cstdio>
using namespace std;
class IntFile
{
public:
int index;
FILE* file; // Error here
IntFile() {}
~IntFile() {}
int mnumbers[10];
int mnumbers2[10];
int value;
// And this whole class does not work
class iterator
{
bool operator ++()
{
file = fopen ("text.txt", "r+b");
fseek (file, 4*index, SEEK_CUR);
fclose(file);
}
bool operator --()
{
file = fopen ("text.txt", "r+b");
fseek (file, (-4)*index, SEEK_CUR);
fclose(file);
}
/*
iterator begin()
{
return ;
}
iterator end()
{
return ;
}
*/
};
};
관련이 있습니다 : https://stackoverflow.com/questions/46243549/going-through-file-using-iterators – NathanOliver
@NathanOliver 정확하지 않습니다. –
'iterator'에는'file'이라는 데이터 멤버가 없습니다. 'IntFile' 안에 중첩되어 있다는 사실은'IntFile' 객체에 대한 연결을 제공하지 않습니다. 또한,'fseek'는 ** 현재 **'FILE *'객체에 적용되며 기본 파일에는 적용되지 않습니다. 파일 열기, 찾기 및 닫기는 효과가 없습니다. –