C++ 读取二进制文件到char*

字符串拼接

    char buf[16] = "dsaas";
    char ss[20] = "dsadas";
    strcat_s(buf, sizeof(buf)+ sizeof(ss), ss);
    cout << buf << endl;

读取二进制文件到char*

#include 
#include 
#include 
#include 
using namespace std;
void main()
{
    string r = "";
    fstream fs(path, ios::in | ios::binary);
    if (!fs.bad())
    {
        fs.open(path, ios::in);

        ostringstream oss;
        oss << fs.rdbuf();
        r = oss.str().c_str();

        fs.close();
    }

    cout << r << endl;
}

你可能感兴趣的:(C++)