我有一个简单的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;
}
答案 0 :(得分:2)
在您的输入上尝试var
wText: WideString;
size: TSize;
begin
//Printer.Canvas.TextOut(x, y, sText);
SetLength(wText, MultiByteToWideChar(1254{28599}, 0, PAnsiChar(sText), Length(sText), nil, 0));
MultiByteToWideChar(1254{28599}, 0, PAnsiChar(sText), Length(sText), PWideChar(wText), Length(wText)));
Windows.ExtTextOutW(Printer.Canvas.Handle, x, y, Printer.Canvas.TextFlags, nil, PWideChar(wText), Length(wText), nil);
size.cX := 0;
size.cY := 0;
Windows.GetTextExtentPoint32W(Printer.Canvas.Handle, PWideChar(wText), Length(wText), size);
Printer.Canvas.MoveTo(x + size.cX, Y);
end;
,其中sed ${n}p | wc
是相关的行号。我的猜测是wc会报告它是4095个字符,或者在4096位有特别的东西。
n
没有缓冲区大小限制。