作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想读入一个名为:abc.txt 的文本文件
文本文件仅包含一个简单的 a、b 和 c,各占一行。
当我使用 Microsoft 编译器编译它时,它编译没有任何问题,并且我得到了我期望的输出(见下文):
a
b
c
(blank line here)
这是我正在使用的 Borland 编译行:
bcc32 -w -ebor.exe main.cpp
这是我正在使用的 main.cpp 文件:
main.cpp
#include <iostream>
#include <fstream>
#include <string>
void printout(const std::string &file);
int main(void)
{
printout("abc.txt");
return 0;
}
void printout(const std::string &file)
{
std::ifstream words;
std::string str;
words.open(file);
while(!words.eof())
{
std::getline(words, str);
std::cout << str << "\n";
}
words.close();
}
我在 Borland 中遇到的确切错误如下:
错误 E2285 main.cpp 17:无法在函数 printout(const std::string &) 中找到“ifstream::open(const std::string)”的匹配项
我也收到警告,但似乎它发生的唯一原因是阻止使用"file"的错误:
警告 W8057 main.cpp 26:函数打印输出中从未使用参数"file"(const std::string &)
非常感谢任何帮助,谢谢。
最佳答案
在 C++11 之前,std::ifstream::open
需要一个 const char *
。用这个。
words.open( file.c_str() );
关于c++ - 适用于 Microsoft : Couldn't find a match for 'ifstream::open' 的 Borland 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15889762/
我是一名优秀的程序员,十分优秀!