C++如果流打开许多文件

C++ ifstream open many files

本文关键字:许多 文件 如果 C++      更新时间:2023-10-16

如果我有大约 19 个txt文件示例文件名: 13.txt如何使用 C++ 中的 easy 方法按顺序打开txt文件。感谢您解决此问题。

for(int i = 0; i < 100; ++i)
{
  std::istringstream iss;
  iss << i << ".txt";
  std::ifstream ifs( iss.str().c_str() );
  if(ifs) {
    // Do something with ifs
  }
}

它非常简单地创建与需要操作的文件一样多的ifstream对象。请注意,因为此任务是资源密集型的