#include <QCoreApplication>#include <QDebug>#include <QFile>#include <QFileInfo>#include <QString>void Write(QString fileName){ QFile mFile(fileName); if (!mFile.open(QFile::WriteOnly | QFile::Text)) { qDebug() << "Could not open the file!"; return; } QTextStream out(&mFile); out << "Hello world!"; mFile.flush(); mFile.close();}void Read(QString fileName){ QFile mFile(fileName); if (!mFile.open(QFile::ReadOnly | QFile::Text)) { qDebug() << "Could not open the file!"; return; } QTextStream in(&mFile); QString mText = in.readAll(); qDebug() << mText; mFile.close();}int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QString mFileName = "C:/myfile.txt"; Write(mFileName); Read(mFileName); return a.exec();}
C++ (Qt)int main( ){ // Read data from the input file QString fileNameIn = "input.txt"; QString content; try { readData( fileNameIn, content ); } catch ( const LogicError &e ) { std::cerr << e.what( ) << std::endl; return 1; } catch ( const FileError &e) { std::cerr << e.what( ) << std::endl; return 1; } catch ( ... ) { std::cerr << "Error: unknown exception" << std::endl; return 1; } // Parse the content to the integer array std::vector<int> arr; try { parseToIntArray( content, arr ); } catch ( const LogicError &e ) { std::cerr << e.what( ) << std::endl; return 1; } catch ( ... ) { std::cerr << "Error: unknown exception" << std::endl; return 1; } // Write data to the output file QString fileNameOut = "output.txt"; try { writeData( fileNameOut, arr ); } catch ( const LogicError &e ) { std::cerr << e.what( ) << std::endl; return 1; } catch ( const FileError &e ) { std::cerr << e.what( ) << std::endl; return 1; } catch ( ... ) { std::cerr << "Error: unknown exception" << std::endl; return 1; } return 0;}