私は通信するサーバーとクライアントを作成しました。クライアントは画像のバイナリデータを送信し、サーバーはそれを受信してファイルに書き込みます。以下に必要なコードを貼り付けました。
std::stringstream binStr;
bytes_received = recv(new_sd, &binStr, sizeof(binStr) ,0);
std::cout << binStr << std::endl;
char buff[1024*1024];
std::string image;
while (!binStr.eof())
{
binStr.read(buff, sizeof (buff));
image.append(buff, binStr.gcount());
}
int id = 1;
std::stringstream ss2;
ss2 << id;
std::string str2 = ss2.str();
std::ofstream img(str2.c_str(),std::ios::binary);
std::cout << image.c_str() << std::endl;
img.write(image.c_str(), image.length());
このコードは、名前が id のファイルを作成しますが、空のファイルです。どうすれば修正できますか?