gpt4 book ai didi

c++ - 如何在 C/C++ 中创建文件数组?

转载 作者:太空宇宙 更新时间:2023-11-04 05:43:28 24 4
gpt4 key购买 nike

在 C/C++ 程序中,我这样做是否正确:

int i;
FILE **files = malloc(numFiles * sizeof(FILE *));
std::string file("foo"), ext(".bar");
char *num[10];

for (i = 0; i < numFiles; i++) {
files[i] = fopen((file + itoa(i, num, 10) + ext).c_str(), "w");
}

这基本上就是我正在做的,但我没有将任何内容写入文件。它们是空白的。

编辑

我已经解决了我的问题。我以为我可能在这里做错了什么,但结果是在其他地方。无论如何,感谢您的回复。

最佳答案

确定它们是空白的,你没有写任何东西,你只是以书写模式打开文件!

您必须使用 fwrite 或 fprintf 函数将数据写入文件,然后使用 fclose 关闭文件。

关于c++ - 如何在 C/C++ 中创建文件数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12041036/

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