如何将上下文附加到文件? [英] How to append context to a FILE?

查看:94
本文介绍了如何将上下文附加到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


在c中,我可以用argv附加打开一个文件,如何在c ++ fstream中附加上下文到

FILE?谢谢!


问候,

Davy

解决方案

>在c中,我可以使用argv append打开一个文件,

如何将上下文附加到c ++中的FILE
fstream?谢谢!




#include< fstream>


int main()

{

std :: ofstream ofs(" file",std :: ios_base :: out | std :: ios_base :: app);


if(ofs) )

{

ofs<< 这是附加的;

}

}


Jonathan


Jonathan Mcdougall写道:

在c中,我可以用argv附加打开文件,
如何将上下文附加到文件在c ++
fstream?谢谢!
#include< fstream>


{std :: ofstream ofs(" file",std :: ios_base ::) out | std :: ios_base :: app);

if(ofs)
{



ofs<< 这是附加的还是没有!; }
}




Abecedarian写道:

Jonathan Mcdougall写道:

>在c中,我可以用argv追加打开一个文件,
>如何在c ++中将上下文附加到FILE
> fstream的?谢谢!



#include< fstream>

int main()
{st / :: ofstream ofs(" file" ;,std :: ios_base :: out | std :: ios_base :: app);

if(ofs)
{


ofs<< 这是附加或不附加!;

}
}




如果您对此有疑问发布的解决方案的有效性,我会

感谢更详细的解释,因为我认为,发布的解决方案

是正确的。从c ++标准,第27.4.2.1.4节[lib.ios :: openmode],

表86 - openmode效果:


app:seek每次写完前结束

out:打开输出


最好


Kai-Uwe Bux


Hello all,

In c,i can open a file with argv append, How to append context to a
FILE in c++ fstream? Thanks!

Regards,
Davy

解决方案

> In c,i can open a file with argv append,

How to append context to a FILE in c++
fstream? Thanks!



# include <fstream>

int main()
{
std::ofstream ofs("file", std::ios_base::out | std::ios_base::app);

if (ofs)
{
ofs << "This is appended";
}
}

Jonathan


Jonathan Mcdougall wrote:

In c,i can open a file with argv append,
How to append context to a FILE in c++
fstream? Thanks!
# include <fstream>

int main()
{
std::ofstream ofs("file", std::ios_base::out | std::ios_base::app);

if (ofs)
{


ofs << "This is appended or not!"; }
}




Abecedarian wrote:

Jonathan Mcdougall wrote:

> In c,i can open a file with argv append,
> How to append context to a FILE in c++
> fstream? Thanks!



# include <fstream>

int main()
{
std::ofstream ofs("file", std::ios_base::out | std::ios_base::app);

if (ofs)
{


ofs << "This is appended or not!";

}
}



If you have doubts about the validity of the posted solution, I would
appreciate a more detailed explanation since I think, the posted solution
is correct. From the c++ standard, clause 27.4.2.1.4 [lib.ios::openmode],
Table 86 -- openmode effects:

app: seek to end before each write
out: open for output

Best

Kai-Uwe Bux


这篇关于如何将上下文附加到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆