下面是将文件全部读入char * buffer
/* fread example: read an entire file */
#include <stdio.h>
#include <stdlib.h>
int main () {
FILE * pFile
long lSize
char * buffer
size_t result
pFile = fopen ( "myfile.bin" , "rb" )
if (pFile==NULL) {fputs ("File error",stderr)exit (1)}
// obtain file size:
fseek (pFile , 0 , SEEK_END)
lSize = ftell (pFile)
rewind (pFile)
// allocate memory to contain the whole file:
buffer = (char*) malloc (sizeof(char)*lSize)
if (buffer == NULL) {fputs ("Memory error",stderr)exit (2)}
// copy the file into the buffer:
result = fread (buffer,1,lSize,pFile)
if (result != lSize) {fputs ("Reading error",stderr)exit (3)}
/* the whole file is now loaded in the memory buffer. */
// terminate
fclose (pFile)
free (buffer)
return 0
}
构建函数芦运建一个string 对象,把 char * buffer 内容存入 程序部分,请自己补充:
#include <windows.h>
#include<iostream>
#include <string>
using namespace std
#include <stdio.h>
// 插入上面搭哗物程序 .....
// 补充
string sss
sss.assign(buffer,result)
cout <<sss <<endl
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)