C++ 讀取二進位制檔案到char*

zsdeus133發表於2018-04-28

字串拼接

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

讀取二進位制檔案到char*

#include <string.h>
#include <fstream>
#include <iostream>
#include <sstream>
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;
}

相關文章