对文件的读写;
来源:互联网 发布:sql server 递归排序 编辑:程序博客网 时间:2024/05/05 08:10
#include <iostream>
#include <fstream>
#include <string>
#include<windows.h>
int main()
{
std::string str;
std::ifstream file("test.txt", std::ios::in | std::ios::ate);
if (file) {
std::ifstream::streampos filesize = file.tellg();
str.reserve(filesize);
file.seekg(0);
while (!file.eof())
{
str += file.get();
}
std::cout << str;
HANDLE hFile = CreateFile("test.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD dword = GetFileSize(hFile, NULL);
char* pCh = new char[dword + 10];
DWORD word;
ReadFile(hFile, pCh, dword +1, &word, NULL);
pCh[dword + 1] = 0;
CloseHandle(hFile);
std::cout << pCh << std::endl;
int x;
std::cin >> x;
return 0;
}
#include <fstream>
#include <string>
#include<windows.h>
int main()
{
std::string str;
std::ifstream file("test.txt", std::ios::in | std::ios::ate);
if (file) {
std::ifstream::streampos filesize = file.tellg();
str.reserve(filesize);
file.seekg(0);
while (!file.eof())
{
str += file.get();
}
std::cout << str;
}
//这里是用的是C++一般的读取整个文件的内容读到str中;
Win32中读取文件的做法;
HANDLE hFile = CreateFile("test.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD dword = GetFileSize(hFile, NULL);
char* pCh = new char[dword + 10];
DWORD word;
ReadFile(hFile, pCh, dword +1, &word, NULL);
pCh[dword + 1] = 0;
CloseHandle(hFile);
std::cout << pCh << std::endl;
int x;
std::cin >> x;
return 0;
}
0 0
- 对文件的读写;
- ]对INI文件的读写
- 对文件的读写操作
- Windows对文件的读写
- java对文件的读写
- Android对文件的读写
- javascript对文件的读写
- C对文件的读写
- IO对文件的读写
- RandomAccessFile 对文件的读写
- 【python】对文件的读写文件
- DELPHI中对INI文件的读写
- [转载]对INI文件的读写
- Java 中对文件的读写操作
- DELPHI中对INI文件的读写
- .Net 对 xml文件的读写
- 关于JAVA对XML文件的读写
- java对excel文件的读写操作
- iOS多线程学习之NSOperation(二)
- 菜鸟成长_01--andriod模拟器sdcard上传图片失败无法显示
- shell编程入门
- 计算机中数值型数据二进制形式存储过程中的原码,反码与补码
- 内部类
- 对文件的读写;
- 漫谈C指针第十讲---参数的地址传递
- 年终总结--不平凡,是因为坚持了平凡
- unsigned int get_svrport(char *, char *, unsigned int);
- BAT及各大互联网公司2014前端笔试面试题--Html,Css篇
- 自写图像标注工具 QT+Opencv
- 字典树
- 设计模式 创建型模式 知识点 小结
- java平台