ifstream 和 ofstream 用法。
outfile << pContent;//不可以用这个,因为不能写完全,比如遇到字符串中出现/0就终止了 bool CTestEn_DecryptDLLDlg::WriteDataFile(CString strFileName, char *pContent, int nLen)
{
ofstream outfile(strFileName, ios::out | ios::binary | ios::ate | ios::app);
if (!outfile)
{
AfxMessageBox(_T("Unable to open outfile"));
return false;
} //for (int i = 0; i < nLen; ++i)
//{
// outfile << pContent[i];
//}
//outfile << pContent;//不可以用这个,因为不能写完全,比如遇到字符串中出现/0就终止了
outfile.write(pContent, nLen);
outfile.close();
} bool CTestEn_DecryptDLLDlg::ReadDataFile(CString strFileName, char *pContent, int &nLen)
{
ifstream inFile(strFileName, ios::in | ios::binary);
if (!inFile)
{
AfxMessageBox(_T("Unable to open inFile"));
return false;
} inFile.seekg(, ios::beg);
//int i = 0;
//while (!inFile.eof())
//{
// inFile.get(pContent[i]);
// ++i;
//}
//nLen = i - 1;
memset(pContent, , nLen);//初始化FileContent
inFile.read(pContent, nLen);//读取数据 inFile.close();//关闭ifstream对像
return true;
}
ifstream 和 ofstream 用法。的更多相关文章
- fstream,ifstream,ofstream 详解与用法
fstream,istream,ofstream 三个类之间的继承关系 fstream :(fstream继承自istream和ofstream)1.typedef basic_fstream< ...
- 关于fstream、ifstream、ofstream读写文本文件、二进制文件详解
fstream.ifstream.ofstream是c++中关于文件操作的三个类 fstream类对文件进行读操作和写操作 打开文件 fstream fs("要打开的文件名",打开 ...
- 详解文件操作(ifstream、ofstream、fstream)[转]
C++ 通过以下几个类支持文件的输入输出: ofstream: 写操作(输出)的文件类 (由ostream引申而来) ifstream: 读操作(输入)的文件类(由istream引申而来) fstre ...
- C++文件操作详解(ifstream、ofstream、fstream)
C++ 通过以下几个类支持文件的输入输出: ofstream: 写操作(输出)的文件类 (由ostream引申而来) ifstream: 读操作(输入)的文件类(由istream引申而来) fstre ...
- 【学习笔记】C++文件操作详解(ifstream、ofstream、fstream)
C++ 通过以下几个类支持文件的输入输出: ofstream: 写操作(输出)的文件类 (由ostream引申而来) ifstream: 读操作(输入)的文件类(由istream引申而来) fstre ...
- ofstream和ifstream详细用法
ASCII和二进制文件的输入输出 First:包含头文件#include <fstream> ASCII输入: 首先要创建一个in-stream对象:ifstream fin(" ...
- 转载:fstream和ifstream详细用法
文件 I/O 在C++中比烤蛋糕简单多了.在这篇文章里,我会详细解释ASCII和二进制文件的输入输出的每个细节,值得注意的是,所有这些都是用C++完成的. 一.ASCII 输出 为了使用下面的方法, ...
- ofstream和ifstream
ofstream(输出流)是从内存到硬盘,ifstream(输入流)是从硬盘到内存. //#include<iostream> #include<fstream> using ...
- 学习c++ofstream和ifstream
定义数据流对象指针 对文件进行读写操作首先必须要定义一个数据流对象指针,数据流对象指针有三种类型,它们分别是: Ifstream:表示读取文件流,使用的时候必须包含头文件"ifstream& ...
随机推荐
- POJ 1029 False coin
http://poj.org/problem?id=1029 题意: 在一堆硬币中有一个假硬币,重量是重是轻不知道.每次称量多个硬币,并给出称量结果.判断依据题目给出的几次称量结果能否找出假硬币. 思 ...
- UVa 437 巴比伦塔
https://vjudge.net/problem/UVA-437 这道题和HDU的Monkey and Banana完全一样. #include<iostream> #include& ...
- Linux——GRUB简单学习笔记
GRUB的配置文件默认为 :/boot/grub/grub.conf # ls -l /etc/grub.conf GRUB配置选项: default定义缺省启动系统 timeout定义缺省等待时间 ...
- hdu 5666 Segment 俄罗斯乘法或者套大数板子
Segment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem ...
- Vim简本
参考链接:http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/ 本文将更简化,只保留其中的精华部分. Level One — ...
- python 元组元素计数
#create a tuple tuplex = , , , , , , , , print(tuplex) #return the number of times it appears in the ...
- 《剑指offer》第十三题(机器人的运动范围)
// 面试题:机器人的运动范围 // 题目:地上有一个m行n列的方格.一个机器人从坐标(0, 0)的格子开始移动,它 // 每一次可以向左.右.上.下移动一格,但不能进入行坐标和列坐标的数位之和 // ...
- Lua中数组的学习
--数组的大小是不固定的 --一维数组的逻辑结构是线性表索引从1开始 array1 = {"Lua", "Tutorial"} , do print(array ...
- 二叉树最大宽度 Maximum Width of Binary Tree
2018-07-27 15:55:13 问题描述: 问题求解: 题目中说明了最后的宽度计算其实是按照满二叉树来进行计算的,也就是说如果我们能够得到每层最左边的节点编号和最右边的节点编号,那么本题就可以 ...
- 雷林鹏分享:Ruby 模块(Module)
Ruby 模块(Module) 模块(Module)是一种把方法.类和常量组合在一起的方式.模块(Module)为您提供了两大好处. 模块提供了一个命名空间和避免名字冲突. 模块实现了 mixin 装 ...