1 致谢
感谢网友roger_77提供的资料
链接如下:
https://blog.csdn.net/roger_77/article/details/1538447/
2 问题描述
今天在继续学习目标检测的代码 遇到一个小问题
需要判断文件是否存在 于是就在想在C++中如何实现这个小功能
然后就找到了上文中说到的资料
3解决方案
测试代码如下:
// Test_VS2013.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include <fstream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
fstream _file;
string path = "D:\\Test\\2.jpg";
_file.open(path, ios::in);
if (!_file)
{
cout << path << " 没有被创建" << endl;
}
else
{
cout << path << " 已经存在" << endl;
}
// 记得要把文件close,当时没有注意,不好意思,,,
system("pause");
return 0;
}
测试结果如下图

测试成功!
本文介绍了一种使用C++来判断指定路径下文件是否存在的方法,并提供了完整的测试代码及运行结果。
1万+

被折叠的 条评论
为什么被折叠?



