gpt4 book ai didi

c++ - fwrite 在大数据上失败

转载 作者:行者123 更新时间:2023-11-30 02:52:53 26 4
gpt4 key购买 nike

嘿,尝试在代码中编译图像并再次将其作为 jpg 输出,但 fwrite 返回 0 并且 img.jpg 保持为空:(

#include <stdio.h>
#include <string>
#include <iostream>

size_t count = 76830;//=length of data

const uint8_t data[] = {0xff,0xd8,0xff,0xe0,0x0,0x10,0x4a,0x46,0x49,0x46.....
0x0,0x7f,0xff,0xd9};

using namespace std;
//use this to saveToFile...
void saveToFile(const char * filename) {
FILE * file = fopen(filename, "rb");
if (file == NULL) {
std::cout << "error opening file" << std::endl;
return;
}


cout << endl << fwrite(data, sizeof(uint8_t), sizeof(data), file); //this line returns 0!!!
fclose(file);
}

int main () {
saveToFile("img.jpg");
}

最佳答案

fopen(filename, "rb");

这将打开文件进行读取,而不是写入。你要

fopen(filename, "wb");
// ^

关于c++ - fwrite 在大数据上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18468912/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com