最好用string这个类
// 从文件中读取字符串
string readfile (const char* filename)
{
FILE* fp = fopen(filename, "rb");
if(!fp)
{
printf("failed to open file! file: %s" , filename);
return "";
}
char* buf = new char[1024*16];
int n = fread(buf, 1, 1024*16, fp);
fclose(fp);
string result;
if(n >= 0)
result.append(buf, 0, n);
delete [] buf;
return result;
}