QT读写文件的问题
代码:voidMainWindow::on_readPushButton_clicked(){QFilefilein("C:/Users/Administrator/De...
代码:
voidMainWindow::on_readPushButton_clicked()
{QFile filein("C:/Users/Administrator/Desktop/readbefore.txt");
if(!filein.open(QIODevice::ReadOnly|QIODevice::Text))
return;
QTextStream in(&filein);
while(!in.atEnd())
{QStringline=in.readLine();
QStringtelnumber="AT+CMGS="+line;}
QFile fileout("C:/Users/Administrator/Desktop/readafter.txt");
QTextStream out(&fileout);
out<<telnumber<<<<"\n";}
error:line was not declared in this scope
请问应该怎么改 展开
voidMainWindow::on_readPushButton_clicked()
{QFile filein("C:/Users/Administrator/Desktop/readbefore.txt");
if(!filein.open(QIODevice::ReadOnly|QIODevice::Text))
return;
QTextStream in(&filein);
while(!in.atEnd())
{QStringline=in.readLine();
QStringtelnumber="AT+CMGS="+line;}
QFile fileout("C:/Users/Administrator/Desktop/readafter.txt");
QTextStream out(&fileout);
out<<telnumber<<<<"\n";}
error:line was not declared in this scope
请问应该怎么改 展开
2个回答
展开全部
QFile in("in.txt");
if(!in.open(QIODevice::ReadOnly | QIODevice::Text)){
return ;
}
QString number;
while(!in.atEnd()){
QString line=in.readLine();
number+="AT+COMGS="+line;
}
QFile out("out.txt");
out.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream outStream(&out);
outStream<<number;
in.close();
out.close();
稍微修改了一下。注意作用域。
if(!in.open(QIODevice::ReadOnly | QIODevice::Text)){
return ;
}
QString number;
while(!in.atEnd()){
QString line=in.readLine();
number+="AT+COMGS="+line;
}
QFile out("out.txt");
out.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream outStream(&out);
outStream<<number;
in.close();
out.close();
稍微修改了一下。注意作用域。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询