需要帮助获取ifstream::open以打开文件并从中获取行
need help to getin ifstream::open to open a file and getline from it
我只是想打开这个文件,并使用getline函数从文件中读取,但我似乎不明白为什么它不起作用。我已经尝试过很多次了,fileOpen变量与我试图打开的文件一起被正确加载,所以我不确定为什么它不能打开,使用getline。我只想能够使用getline读取文件,所有这些都是在递归函数中完成的,最终读取目录中的所有文件。如果你需要更多关于我到底在做什么的信息,请告诉我。
string line;
ifstream file;
string fileOpen;
bf::directory_iterator dirIter ( fullPath ); //fullPath is type bf::path, passed into the function
fileOpen = (dirIter->path().filename());
file.open(fileOpen);
getline(file, line);
path::filename
函数返回基本文件名。如果您的路径是"foo\bar.txt",path::filename
将返回"bar.txt"。因此,除非"foo\"在当前目录中,否则该文件可能不存在。
你更可能要找的是:
file.open(dirIter->path().native());
或者,您可以使用boost::filesystem iostream types:
#include <boost/filesystem/fstream>
bf::ifstream file;
bf::directory_iterator dirIter ( fullPath ); //fullPath is type bf::path, passed into the function
file.open(dirIter->path());
相关文章:
- 获取文件数据预处理器宏
- 如何在Windows内核中获取文件大小
- 从 C 中的变量获取文件的路径,C++
- 如何使用 C/C++ 和 system() 系统调用以外的其他方法在 Linux 中获取文件功能?
- 如何使用 jpeglib.h 获取文件是否为 JPEG 类型
- 谁能告诉我,程序中的错误是什么?该程序仅用于获取文件扩展名
- 我需要通过窗口句柄(HWND)获取文件,我该怎么办?
- 如何用C++部分地获取文件中的行
- 使用内置的Windows方法获取文件夹的内容
- 在 Apache Velocity 模板语言中获取文件目录
- 如何在C#或C++中获取文件或文件夹的有效权限?有什么 API 吗?
- 对字符求和并减去以获取文件
- 从 FutureAccessList 同步获取文件夹路径
- 通过HTTPS从POCO StreamCopier获取文件下载进度
- 如何使用C 17获取文件大小
- getline 无法获取文件的第一行
- 如何使用 Win API 获取文件夹中的文件列表(带过滤器)
- 无法从零MQ ZMQ_SERVER套接字中获取文件描述符
- HttpQueryInfo 获取文件大小
- 通过文件资源管理器获取文件夹目录