1.fstream.STL
来源:互联网 发布:淘宝男鞋品牌排行榜 编辑:程序博客网 时间:2024/06/05 23:52
1.回车
STL里有个fstream类,用来读写文件,对于文本文件的回车处理得注意个问题,那就是开方模式中要使用ios_base::binary,才能正确的进行读写。读出数据时要有启用这个模式,写的时候也一样。
- const char* filename="a.txt";
- fstream file;
- file.open(filename, ios_base::in | ios_base::binary);
- if (file.fail()) goto LB_FAIL;//失败
- //do something with file
- file.flush();
- file.close();
- //-----------------------------------
- file.clear(); //清除对象中保留的状态
- file.open(filename, ios_base::out | ios_base::binary);
- //do something with file
- file.flush();
- file.close();
- file.clear;
- LB_FAIL: return FALSE;
2.长度
文件长度可用来获取。目前没有办法缩短文件,如果改写后数据长度比原来的小,那么用ios_base::trunc清空内容再重新写入新数据。注:超笨!!!
- #include <fstream>
- const char* filename="a.txt";
- fstream file;
- file.open("a.txt", ios_base::in | ios_base::binary);
- file.seekg(0, fstream::end);
- cout << "file size: " << file.tellg() << std::endl;
- 1.fstream.STL
- fstream用法 STL
- fstream用法 STL
- C++ STL fstream的一个妙用
- STL之文件读写类fstream
- fstream
- fstream
- fstream
- fstream
- fstream
- fstream
- fstream
- fstream
- fstream
- fstream
- fstream
- fstream
- 用C++中STL提供的fstream和stream_iterator读写二进制文件。
- Security Tutorials系列文章第六章:Validating User Credentials Against the Membership User Store
- 详细讲解Quartz.NET
- C#实现Web文件上传的两种方法
- Oracle中SQL语句的性能优化
- 构造 Create IRP
- 1.fstream.STL
- 在ubuntu 下安装insight
- 远程复制的几个工具介绍!
- 谁知道怎样才能找到一个外国人进行口语训练
- 央视晚间新闻出现口误 澳大利亚首都变悉尼
- 新改的jmail发送邮件代码,有解释
- PowerShell 2.0 CTP:使用Select-String查找文本
- C#文件操作点点滴滴
- js的继承