如何在包含文本的 QFile 中找到特定字符?
例如,我的文件中某处写有“$5000”。想要找到“$”符号,所以我会意识到我已经达到了这个数字。
我尝试通过将 1 作为 maxlen 来使用 QString QTextStream::read(qint64 maxlen) :
QFile myfile("myfile.txt");
myfile.open(QIODevice::ReadWrite | QIODevice::Text);
QTextStream myfile_stream(&myfile);
while(! myfile_stream.atEnd())
{
if( myfile_stream.read(1) == '$')
{
qDebug()<<"found";
break;
}
}
我得到“错误:从'char'到'const char*的无效转换”
我也尝试使用 operator[] 但显然它不能用于文件。