g ++ (버전 4.6.3)에서 다음 코드의 여러 버전을 사용해 보았습니다. 각각의 경우에바이너리 파일을 잘못 읽거나 컴파일러 버그를 읽는 중?
int main(int argc,char *argv[])
{
std::string fname(argv[1]);
std::cout<<"fname is"<<fname<<std::endl;
// std::fstream f(fname.c_str(),
std::fstream::in|std::fstream::out|std::fstream::binary);
std::fstream f(fname.c_str(),std::ios::in|std::ios::out|std::ios::binary);
unsigned char b[512];
memset(b,0xff,512);
std::cout<<f.tellg()<<std::endl;
f.seekg(0,std::ios::beg);
std::cout<<f.tellg()<<std::endl;
f.read((char *)b,512);
for(int ii=0;ii<sizeof(sector0);ii++)
std::cout<<std::hex<<(int)(b[ii]) <<" ";
std::cout<<std::endl;
}
이 결과는 I 소스 코드 (샘플 ASCII)의 파일 이름을 전달 동일 tellg은 1보고하고 버퍼 파일 일치한다. 실행 파일의 파일 이름 (예제 바이너리)을 전달하면 tellg은 -1을보고 덤프는 모두 ff입니다.
제가 잘못했거나 컴파일러 버그입니까?
힌트 : 컴파일러 버그가 아닙니다. –
가'std :: ios :: out' 모드에서 열리고 있습니까? – keety
keety. 이 부분이 아니라 프로그램의 뒷부분. 물론 샘플을 꺼냈다. –