ofstream outFile;
string filepath="D:/qtprogram/student_grade_manager/ModifiedGrade"+tempTime+".txt";
outFile.open(filepath.c_str());
QString a="学号",b="姓名";
outFile<<a.toLocal8Bit().toStdString()<<" "<<b.toLocal8Bit().toStdString();
由于QT中的一个中文字符占3字节,需要先使用toLocal8Bit()将QString转化为两字节的中文字符,然后再输出到文件中。