gpt4 book ai didi

c++ - fstream 接受文件夹路径并且是 (`good()==1` )

转载 作者:行者123 更新时间:2023-11-28 03:18:22 25 4
gpt4 key购买 nike

#include<iostream>
#include<fstream>

int main()
{

std::string folderPath("./");

std::string fileFoo = folderPath + "";
std::string fileBar = folderPath + "nonexisting_file";

std::ifstream foo(fileFoo.c_str());
std::ifstream bar(fileBar.c_str());

std::cout << foo.good() << std::endl;
std::cout << bar.good() << std::endl;

}

输出:

1
0
  1. 流文件路径是目录是什么意思。
  2. 在这种情况下如何检查 fstream 是否可读,因为 good() 不起作用。

编辑:

这似乎是相关的:

平台:Linux (Ubuntu 12.04)

最佳答案

根据文件系统的不同,目录很容易一种文件并且没有太大区别。除非您使用某些第三方库,否则处理您尝试做的事情将不会与平台无关,我强烈建议您使用 boost::filesystem

关于c++ - fstream 接受文件夹路径并且是 (`good()==1` ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16196503/

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