簡體   English   中英

在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)'的匹配項

我也收到了一個警告,但似乎它發生的唯一原因是由於錯誤阻止了“文件”的使用:

警告W8057 main.cpp 26:參數'file'從不在函數printout中使用(const std :: string&)

非常感謝任何幫助,謝謝。

在C ++ 11之前, std::ifstream::open需要一個const char * 用這個。

words.open( file.c_str() );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM