1. 程式人生 > >c++讀取txt檔案到string

c++讀取txt檔案到string

string str_native_json("");


FILE* file;
longlSize;
char*szBuf;


file = fopen("native_video.txt", "r+");
if(file)
{
fseek(file, 0, SEEK_END);
lSize = ftell(file);
fseek(file, 0, SEEK_SET);
szBuf = new char[lSize + 1];
fread(szBuf, 1, lSize, file);
fclose(file);
szBuf[lSize] = 0;
str_native_json = szBuf;
delete szBuf;