vc 各种读取txt文件的方法
2012-06-16 10:30
411 查看
一、
CStdioFile
二、
FILE* f = fopen("file name", "mode");
char buff[size];
fread(buff, size, 1, f);
fclose(f);
三、
//用MFC读文件
CFile file("yourfile.txt",CFile::modeRead);
char *pBuf;
int iLen=file.GetLength();
pBuf =new char[iLen 1];
file.Read(pBuf,iLen);
pBuf[iLen]=0;
file.Close();
MessageBox(pBuf);
四、
//用C SDK 读文件
HANDLE hFile;
hFile=CreateFile("2.txt",GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
char ch[100];
DWORD dwReads;
ReadFile(hFile,ch,100,&dwReads,NULL);
CloseHandle(hFile);
ch[dwReads]=0;
MessageBox(ch);*
五、
用C读文件
FILE *pFile=fopen("1.txt","rb");
char *pBuf;
fseek(pFile,0,SEEK_END);//移动文件指针到文件末尾
int len=ftell(pFile);//获取当前文件指针在文件中的偏移量,Gets the current position of a file pointer.offset
pBuf=new char[len];
rewind(pFile);//将指针移动到文件头,Repositions the file pointer to the beginning of a file
//也可以用fseek(pFile,0,SEEK_SET);
fread(pBuf,1,len,pFile);
pBuf[len]=0;
fclose(pFile);
MessageBox(pBuf);
CStdioFile
二、
FILE* f = fopen("file name", "mode");
char buff[size];
fread(buff, size, 1, f);
fclose(f);
三、
//用MFC读文件
CFile file("yourfile.txt",CFile::modeRead);
char *pBuf;
int iLen=file.GetLength();
pBuf =new char[iLen 1];
file.Read(pBuf,iLen);
pBuf[iLen]=0;
file.Close();
MessageBox(pBuf);
四、
//用C SDK 读文件
HANDLE hFile;
hFile=CreateFile("2.txt",GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
char ch[100];
DWORD dwReads;
ReadFile(hFile,ch,100,&dwReads,NULL);
CloseHandle(hFile);
ch[dwReads]=0;
MessageBox(ch);*
五、
用C读文件
FILE *pFile=fopen("1.txt","rb");
char *pBuf;
fseek(pFile,0,SEEK_END);//移动文件指针到文件末尾
int len=ftell(pFile);//获取当前文件指针在文件中的偏移量,Gets the current position of a file pointer.offset
pBuf=new char[len];
rewind(pFile);//将指针移动到文件头,Repositions the file pointer to the beginning of a file
//也可以用fseek(pFile,0,SEEK_SET);
fread(pBuf,1,len,pFile);
pBuf[len]=0;
fclose(pFile);
MessageBox(pBuf);
相关文章推荐
- asp.net实现从Txt文件读取数据到数据视图的方法
- matlab的各种数据读取(txt,dat,mat等格式),文件打开关闭
- VC++实现CStdioFile写入及读取文件并自动换行的方法
- Matlab中读取txt文件的几种方法
- C#控制台基础 streamreader 中的readline方法读取指定txt文件的第一行
- matlab 读取文件各种方法
- 文件读取方法(txt.excel)
- java读取文件的各种方法汇总笔记
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例 .
- java — 读取txt文件的方法
- java 读取 properties文件的各种方法
- Java 各种读取文件方法以及文件合并
- Java读取TXT文件的方法
- 读取TXT文件内容的方法
- Matlab中读取txt文件的几种方法
- asp.net实现从Txt文件读取数据到数据视图的方法
- unity中四种读取txt文件的方法和一种写入txt方法
- C#控制台基础 streamreader 中的readline方法读取指定txt文件的所有行
- sql 读取txt 文件内容,并写入sql的方法
- Python读取txt文件数据的方法(用于接口自动化参数化数据)