ChinaUnix.net
相关文章推荐:

vc fstream 要不要 显式关闭

通常open一个流以后应该调用close。但是,fstream对象析构时,也会关闭流。为什么后面的方法不好呢?谢谢。

by grizzly - C/C++ - 2007-06-08 10:58:34 阅读(3634) 回复(15)

相关讨论

网 站: http://edu.teamsourcing.com.cn 一、 引言   我们在上网浏览时,有时访问到某些网站的网页时会自动弹出一些广告窗口,甚至有不少个人主页为了利用网络广告来赚钱一下同时弹出几个甚至十几个广告窗口。这些窗口一个一个的关掉十分麻烦,而且如果不关的话又会占用大量的系统资源,所以不少人对此深恶痛绝,作为程序员可以利用自身技术优势根据自己的实际需要编制一些很适合自己的小工具。因此本文就对如何通过软件编程来...

by tsjoy - C/C++ - 2008-09-16 10:47:08 阅读(354) 回复(0)

以读写方打开一个文件,刚开始可以往里卖弄写内容,用get读几个字符后,再往里写就写不进去了,怎么回事啊,难道读写不能同时进行?

by boldeagle - C/C++ - 2009-09-01 09:37:55 阅读(1125) 回复(3)

要用一个文件作为配置文件,比如config.txt,内容: ip: 10.0.0.111 port: 2222 现在要写程序,读取和修改配置参数。 如果用fstream来实现的话。读入好办,用>> 就可以了。但是修改有点麻烦。比如读入string 10.0.0.111后,怎样修改这个字串呢?初步的想法是写指针(用seekp())回退size()个位置,然后再写。可是有个问题,后写的字串长度可能超过原来字串长度,造成缓冲区溢出。这样需要把原来的字串留一些空格,保证最大情况...

by wishel - C/C++ - 2008-10-21 10:26:53 阅读(1164) 回复(6)

使用stl,就意味着告别熟悉的c-style编程方,对文件的处理也毫不例外. fstream可以用来对文件进行处理,它象对待数据流一样对待文件. 以下给出一个例子.关键是事先要创建fstream.out文件,哪怕是个空文件,也要先创建.因为fstream不会为你创建. #include #include int main ( ) { using namespace std; // create a bi-directional fstream object fstream inout("fstream.out"); // output c...

by pearma - HP文档中心 - 2005-04-05 16:57:27 阅读(935) 回复(0)

如果是如下代码: [code] fstream sfs; sfs.open("test.txt"); [/code] test.txt文件原来是没有的,像上面的这段代码就没有新生成test.txt文件。 把代码改成: [code] ofstream sfs; sfs.open("test.txt"); [/code] 就可以了,怎么回事啊

by joyue - C/C++ - 2007-03-12 15:38:25 阅读(992) 回复(2)

class A{ fstream fout; } class B{ setF( ? ){ fout = ?} fstream fout; } 要求将A中的fout传送给B中的fout.

by wys0436 - C/C++ - 2007-01-10 14:23:45 阅读(2401) 回复(14)

什么时候需要调用它? 调用它会产生什么结果? 希望解释的详细些。 谢谢!!

by vaqeteart - C/C++ - 2007-10-26 18:28:17 阅读(5149) 回复(8)

以下两段代码 代码一 [code] int main() { fstream file; file.close(); file.open( "test" , std::ios_base::out ); file<<"adsfasf"; file.close(); system( "Pause" ); return 0; } [/code] 代码二 [code] #include <fstream> int main() { fstream file; file.open( "test" , std::ios_base::out ); file.close(); file.open( "test2" , std::ios_base::out ); file<<"adsfasf"; file.close(); system( ...

by zzdts - C/C++ - 2007-06-10 01:21:30 阅读(1777) 回复(5)

ifsteam ifs("aa.txt"); string aa; while(ifs>>aa) {} ..... 这样默认是以空格隔开的,现在想用别的字符分割,不如说‘#’,该怎么办啊? 有没有相关的设置,可以直接改成按“#”吸取? getline的方不想用,有点麻烦。。 请指教,谢谢:)

by pbridge - C/C++ - 2007-04-19 14:02:14 阅读(988) 回复(2)

#include #include #include <fstream> using namespace std; int main () { fstream file; file.open("mem.bin", ios::out|ios::in|ios::binary); char *mem = new char[10]; memset(mem, 'x', 10); if(file.is_open()) { file.write(mem, 10); file.close(); } else { cout<<"Unable to open file!"<

by JustUSTC - C/C++ - 2006-12-03 20:30:16 阅读(3911) 回复(10)