c++ - 如何在 C++ 中计算文件的行数?

标签 c++ file-io io fstream ifstream

如何使用标准类 fstreamifstream 计算行数?

最佳答案

这个怎么样:-

  std::ifstream inFile("file"); 
  std::count(std::istreambuf_iterator<char>(inFile), 
             std::istreambuf_iterator<char>(), '\n');

关于c++ - 如何在 C++ 中计算文件的行数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3072795/

相关文章:

c++ - 从标准输入 C++ 读取数百万整数的最快方法?

windows - 创建目录并通过发出一个 IRP 获取句柄

c - 在 Linux 上使用 fgets() 读取带有 DOS 行结尾的文件

c++ - 如何为多个客户端连接实现服务器等待循环

c# - VS : Make C++ project build automatically when dependant C# project is built

c++ - C++ 中的字符串 : Problems with good() and get()

haskell - 提取 IO 中的 Maybe 值

c++ - 使用 C++ IO istream 对象读取导致无限循环

java - 如何将输入流复制到需要输出流的 Apache TeeOutputStream?

c++ - 'boost::operator ==' : 4个重载有相似的转换