나는 다음 코드를 가지고 꽤 잘 작동한다. (꽤 느리다는 것 외에는별로 신경 쓰지 않는다.) 그것은 infile의 전체 내용을 outfile에 쓰는 것이 직관적 인 것처럼 보이지 않습니다.ifstream :: rdbuf()는 실제로 무엇을합니까?
// Returns 1 if failed and 0 if successful
int WriteFileContentsToNewFile(string inFilename, string outFilename)
{
ifstream infile(inFilename.c_str(), ios::binary);
ofstream outfile(outFilename.c_str(), ios::binary);
if(infile.is_open() && outfile.is_open() && infile.good() && outfile.good())
{
outfile << infile.rdbuf();
outfile.close();
infile.close();
}
else
return 1;
return 0;
}
어떤 통찰력이라도 있습니까?
나는'close()'에 대한 명시 적 호출이 필요 없다고 덧붙일 것이다. 어쨌든 파괴자는 똑같이 할 것입니다. 그리고 그것은 몇 줄을 절약합니다. ;) –