QT中文件读写操作的问题
QFile *arc=new QFile("d:\\arc.txt"); arc->open(QIODevice::ReadWrite|QIODevice::Text); QTextStream in(arc); QTextStream out(arc); edge **matrix; QString number; int startTime[2]; int arriveTime[2]; int startCity; int arriveCity; int price; int i,j,k=8; in<<k<<endl; for(i=0;i<8;i++) in<<"1111"<<" "<<i<<" "<<i+1<<" "<<i+2<<" "<<i+3<<" "<<1<<" "<<2<<" "<<10<<"\n";cout<<k; out>>k;//在用in写入后用out读出第一个数据 for(i=0;i<8;i++) { out>>number>>startTime[0]>>startTime[1]>>arriveTime[0]>>arriveTime[1]>>startCity>>arriveCity>>price; cout<<number.toStdString()<<" "<<startTime[0]<<" "<<startTime[1]<<" "<<arriveTime[0]<<" "<<arriveTime[1]<<" "<<startCity<<" "<<arriveCity<<" "<<price<<endl; } return 0;Q_DECL_EXPORT int main(int argc, char *argv[]){ QFile *arc=new QFile("d:\\arc.txt"); arc->open(QIODevice::ReadWrite|QIODevice::Text); QTextStream in(arc); QTextStream out(arc); edge **matrix; QString number; int startTime[2]; int arriveTime[2]; int startCity; int arriveCity; int price; int i,j,k=8; in<<k<<endl; for(i=0;i<8;i++) in<<"1111"<<" "<<i<<" "<<i+1<<" "<<i+2<<" "<<i+3<<" "<<1<<" "<<2<<" "<<10<<"\n"; arc->close(); //close一次后再打开 arc->open(QIODevice::ReadOnly); out>>k; for(i=0;i<8;i++) { out>>number>>startTime[0]>>startTime[1]>>arriveTime[0]>>arriveTime[1]>>startCity>>arriveCity>>price; cout<<number.toStdString()<<" "<<startTime[0]<<" "<<startTime[1]<<" "<<arriveTime[0]<<" "<<arriveTime[1]<<" "<<startCity<<" "<<arriveCity<<" "<<price<<endl; } cout<<k; return 0;}