我正在使用 WinSock 从 Internet 下载我的文件。
这里的代码演示了我从 header 中获取内容大小,而不是删除 header 并将其余部分写入应用程序。 FileDownload1.write(...) 它会引发访问冲突读取错误。
这段代码有什么问题吗? (我习惯了 C 风格的字符串,所以我还不是 100% 熟悉 C++ 标准字符串。
这是我的一些代码:
DWORD WINAPI DownloadFile(LPVOID VoidAtt){
...
postion = TextBuffer.find("Content-Length: ", 0);
std::string LengthOfFile = TextBuffer.substr(postion + strlen("Content-Length: "), 7);
int FileSize = std::stoi(LengthOfFile, nullptr, 10);
postion = TextBuffer.find("\r\n\r\n", 0);
std::string memoryblock = TextBuffer.substr(postion + 4, -1);
std::ofstream FileDownload1;
FileDownload1.open("64bit1.m4a", std::ios::out | std::ios::binary);
FileDownload1.write(memoryblock.c_str(), FileSize);
FileDownload1.close();
SetWindowTextA(hTextBox, &TextBuffer[0]);
}
如果你需要它,请告诉我,(但是完整的源代码有点乱,因为我只是想搞清楚如何下载文件并将其成功写入计算机。
最佳答案
关于C++ FStream 抛出异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35478664/