简而言之,我双击其文件中的 image1 并打开它。我运行下面的代码打开 image1 但什么也没有出现。所以我再次进入带有 image1 的文件,双击它,Windows 照片查看器说,“Windows 照片查看器无法显示这张图片,因为文件是空的。”我用另外两个测试图像做了这个,同样的事情正在发生。没有丢失任何重要内容,但此方法似乎正在删除它试图打开的任何文件,我很好奇为什么以及如何修复它。
#include <iostream>
#include <fstream>
#include <chrono>
#include <thread>
void main()
{
std::ofstream imagetest;
imagetest.open("C:\\Users\\Filepath\\image1.jpg");
std::chrono::milliseconds dura(2000);
std::this_thread::sleep_for(dura);//Kept the sleep in because I didn't know if having the console up would affect the file/image from opening.
}
最佳答案
C++ 的级别低于脚本。打开并不意味着开始。 您必须使用 START C:\Users\Filepath\image1.jpg 执行批处理脚本。 或者学习更多的库来用 C++ 做这件事...
关于C++打开文件似乎在运行后破坏了文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26388393/