string filename = "1.txt";
    ifstream fin;
    fin.open(filename);

上述语句会产生如下错误:

error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)

原因是C++的string类无法作为open的参数。

解决方案:使用C的字符串。

例:

    char filename[10];
    strcpy(filename, "1.txt");
    ifstream fin;
    fin.open(filename);


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-23
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案