sourceFile.open(filepath);

sourceFile.open(filepath);

本文关键字:filepath open sourceFile      更新时间:2023-10-16

可能的重复:
C 的参数类型ifstream :: Open()
C 使用字符串作为打开文件路径的ifstream错误。

有什么问题
ifstream sourceFile;
sourceFile.open(filepath);

我正在得到一些信息:

无匹配功能呼叫ifstream::open(string&)

怎么了?

相同
ifstream sourceFile(filepath)

filepath是字符串

从C 11开始,iostreams可以将string作为命名要打开的文件的参数 - 但这是在C 11中添加的,因此有很多库''t包括它。更新到您的编译器/库的最新版本可能的帮助(但再一次,我怀疑支持甚至是通用的)。

看起来filepathstringOpen仅采用原始指针。这样做-Open(filepath.c_str());

它需要char* filename,而不是 String 作为参数。

sourceFile.open(filepath.c_str());

The Function is std::ifstream::open
    void open ( const char * filename, ios_base::openmode mode = ios_base::in );

参考