ifstream :: rdbuf()是什么? [英] What does ifstream::rdbuf() actually do?
本文介绍了ifstream :: rdbuf()是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码,它的工作相当不错(除了事实,它是相当缓慢,但我不在乎)。这看起来不直观,这会将infile的整个内容写入outfile。
I have the following code and it works pretty good (other than the fact that it's pretty slow, but I don't care much about that). It doesn't seem intuitive that this would write the entire contents of the infile to the outfile.
// 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;
}
任何洞察力?
推荐答案
是的,它在标准中指定,它实际上很简单。 rdbuf()
只是返回指向给定 [io]的基础
object。 basic_streambuf
stream
Yes, it's specified in the standard and it's actually quite simple. rdbuf()
just returns a pointer to the underlying basic_streambuf
object for the given [io]stream
object.
basic_ostream< ...>
对于指向 basic_streambuf< ...>
的指针的 code> code> $
$ c> basic_streambuf< ...>
。
这篇关于ifstream :: rdbuf()是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文