小编CPP*_*NEW的帖子

C ++中getline的缓冲区大小限制

我有一个简单的C ++程序,它逐行读取文件。有些行包含超过20000个字符。以下程序只能读取这些大行的4095个字符。我认为这是由于缓冲区大小的限制。阅读大字句的解决方案是什么?

// reading a text file
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;

    int main () {
      string line;
      ifstream myfile ("new.fasta");
      if (myfile.is_open())
      {
        while ( getline (myfile,line) )
        {
          cout << line.length() << '\n';
        }
        myfile.close();
      }

      else cout << "Unable to open file";

      return 0;
    }
Run Code Online (Sandbox Code Playgroud)

c++ file getline

5
推荐指数
1
解决办法
1179
查看次数

标签 统计

c++ ×1

file ×1

getline ×1