rt,用c++如何读取二进制文件到一个string类型中,
急求,急求
如下代码,先在string 中分配大小,然后读取,如果要显示字符串中的内容,需要将内存中的内容转换为16进制或者其他的显示方式。
#include <stdio.h>
#include <string>
using namespace std;
int main(int argc , char** argv)
{
string s;
FILE *fp = fopen("c:\\test\\xx.exe","rb");
if(fp)
{
fseek(fp,0,SEEK_END);
int len = ftell(fp);
fseek(fp,0,SEEK_SET);
s.resize(len);
fread((void*)s.data(),1,len,fp);
fclose(fp);
}
else
{
printf("fopen error\n");
}
return 0;
}
string str;
char *pStr="hello myFriend";
str+=pStr