【问题标题】:Opening a txt.file in c++在 C++ 中打开一个 txt.file
【发布时间】:2014-08-31 18:11:01
【问题描述】:

我正在尝试在 C++(Visual Studio)中打开一个简单的 txt.file,但只是触发了“else”。 code.txt 与源文件中的主文件一起包含在内。这或多或少是这样的

#include <iostream>
#include <fstream>

int main()
{
  std::ifstream file("codes.txt");
  if (file.is_open())
  { 
    std::cout << "success" << std::endl;
  }
  else 
  {
    std::cout << "Unable to open file" << std::endl;
  }
}

【问题讨论】:

  • 如果您在任何编辑器中打开了文件,请尝试关闭它并再次运行程序。代码看起来正确。另外,请检查文件是否在运行程序的目录中。
  • 你有什么经验吗?我必须做的不仅仅是用 txt 文件“添加现有对象”。喜欢在节目中提及它?

标签: c++ ifstream


【解决方案1】:

txt 文件在程序文件夹中不存在。包含后完美运行。

【讨论】:

    猜你喜欢
    • 2017-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-16
    • 2014-04-29
    • 1970-01-01
    • 2021-07-01
    • 1970-01-01
    相关资源
    最近更新 更多