2011-09-14 2 views
0

다음 코드 블록에서 다음과 같은 출력이 나타납니다.쓰기 위해 바이너리 파일을 여는 오류 : 'std :: ios_base :: failure'의 인스턴스를 던진 후에 호출 된 종료.

 //create file for writing 
cout << "'" << filename.c_str() << "'" << endl; 
    string outfile = filename.append(".bin"); 
cout << "'" << outfile.c_str() << "'" << endl; 
    fstream *binfile; 
    binfile->open (outfile.c_str(), ios::out | ios::binary); 

인쇄 :

'myfile.tmp' 
'myfile.tmp.bin' 
terminate called after throwing an instance of 'std::ios_base::failure' 
    what(): basic_ios::clear 

무엇을 의미합니까?

감사

답변

1

:

fstream binfile("filename", fstream::in | fstream::out | fstream::binary); 

를 다음 호출 :

fstream *binfile; 

이 작업을 수행해야 포인터에 대한 필요가

binfile << "write here to file"; 

binfile.close(); 

없다 이리.

+0

이상. 나는 그것을 직접 함수에 전달할 수 있도록 그렇게했다. 그것을 고치고 참조를 전달하는 것만으로도 효과가있는 것처럼 보였습니다. – Derek

+1

@Derek, 코드에 대한 또 다른 문제점으로 포인터를 '새롭게'만들지 못했습니다. –

+1

@Derek : 포인터가 뭔가를 가리 키지 않았고 선언 후에도 정의되지 않았습니다. –

관련 문제