Open text file for write-operation : QFile « Qt « C++






Open text file for write-operation

  

#include <QFile>
#include <QTextStream>


int main()
{
    QFile file("out.txt");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
        return 1;

    QTextStream out(&file);
    out << "The magic number is: " << 49 << "\n";
}

   
    
  








Related examples in the same category

1.Create QFile from file path
2.Create file with QFile
3.Open QFile with WriteOnly flag
4.Output with QFile
5.Check file existance and file name with QFile
6.Open a text file in read-only mode
7.Open binary file for write-operation
8.Read file till file end
9.Read text file line by line
10.Read byte array from text file