在Microsoft中起作用的Borland错误:找不到"ifstream::open"的匹配项
Borland error that works in Microsoft: Couldn't find a match for 'ifstream::open'
我想读取一个名称为: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:函数printout(const std::string &)中从未使用参数'file'
在c++ 11之前,std::ifstream::open
需要const char *
。使用这个。
words.open( file.c_str() );
相关文章:
- ifstream什么都没读
- ifstream文件在从行中读取时被清除
- std::ifstream::read 不会读取所有 512 字节,并设置 EOF 和失败位
- 将 ifstream 拆分为 n 个流?
- 如何将 std::ifstream 转换为 std::basic_istream<CharT, Traits>&?
- 我在 ifstream input_file(文件名)行中收到错误"no matching function to call";
- 尝试打开 ifstream 时出现"Incomplete type"错误
- 是否可以在没有真实文件的情况下创建 ifstream
- Poco::Net::FTPClientSession 在 open() 方法上挂起 129 秒,如果 ftp 主机不存
- 虽然循环不读取整个 ifstream 文件
- Node.js fs.open() 在尝试打开 4 个以上的命名管道 (FIFO) 后挂起
- C++:std::ofstream 方法 open() 在第二次迭代时擦除打开的 ifstream 文件
- ifstream::open()真正的作用是什么
- 使用.open()成员函数C++的ifstream数组的错误访问代码
- 将宽字符串与 ifstream::open 一起使用,或者将多字节字符串与 CreateProcess 一起使用
- 从popen到ifstream.open的文件输出列表
- 当参数是目录时,ifstream open() 不会设置错误位
- 在Microsoft中起作用的Borland错误:找不到"ifstream::open"的匹配项
- ifstream.open()未打开文件
- 需要帮助获取ifstream::open以打开文件并从中获取行