如何写一个完整的字符串的文件? [英] How to write a full string to a file?

查看:96
本文介绍了如何写一个完整的字符串的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows编程中的权利,但便携code未免太欢迎。

I'm programming in Windows right now, but portable code would be welcomed too.

我现在使用是的fwrite(4),但此功能需要被写入到文件中的元素的最大数量。我可以使用的strlen(1)在这里,但我想知道是否有任何更好的方法来做到这一点。

What I'm using right now is fwrite(4), but this function needs a maximum number of elements to be written to the file. I can use strlen(1) here but I'd like to know if there is any better way to do this.

推荐答案

使用的fputs 来代替:

FILE * f = fopen( "myfile.txt", "w" );
fputs( "Hello world\n", f );

这篇关于如何写一个完整的字符串的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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