我想知道是否有任何功能或方法可以首先检查文件是否已创建
I want to know is there any function or method to check first either file is created or not
我想知道是否有任何函数或方法可以首先检查文件是否已创建,如果它已创建,则读取信息,否则跳过文件读取过程。
bool file_does_exist(const std::string &filename) {
return std::ifstream(filename);
}
您只需打开文件即可读取
std::fstream fs;
fs.open ("test.txt", std::fstream::in);
然后检查一切是否正常
if(fs.good())
//...
这个问题不是太清楚,但你的意思是这个吗?
std::ifstream file("file_name.ext");
if (file)
{
read_from(file);
}
相关文章:
- 检查输入是否不是整数或数字
- 检查值是否在集合p1和p2中,但不在p3中
- 检查 std::shared_ptr<> 的当前底层类型是否为 T
- 在c++中检查长方体是否尽可能快地重叠(无迭代)
- 如何检查线程是否锁定
- C++LDAP检查用户是否是特定组的成员
- 检查TCHAR数组输入是否为带符号整数C++
- 如何检查QList中是否存在值
- 检查函数返回类型是否与STL容器类型值相同
- 检查是否以特定精度给出双精度
- 检查向量是否具有所有可能的字符组合
- 检查注册表项是否链接到(或副本)另一个注册表项
- 地图计数确实很重要,或者只是检查是否存在
- 检查 2 棵树是否具有相同的顺序
- std::next 是否检查我们是否已经在容器的末尾?
- "!" "== 0"是否检查 int 是否是 0 的好做法?
- 我是否检查是否存在带或不带参数的宏函数
- dynamic_cast是否检查被查询对象的type_info对象,或者递归地检查
- 在VS2010中编译c++ 11中的代码时,std::function()是否检查类型
- 如果第二个参数"0",strcmp 是否C++检查字符串中的每个值?