Hi, I need to write some text to a file and i am trying to use QFile however i have a few problems, first i thought it was my code so i created a new project with just the example given in the QT documentation and i cant even get that to work! So using the example (where i replace out.txt with D://out.txt to write to my D drive):
#include <QtCore/QCoreApplication>
#include<QTextStream>
#include<QFile>
int main()
{
QFile file("D://out.txt");
return;
out << "The magic number is: " << 49 << "\n";
}
#include <QtCore/QCoreApplication>
#include<QTextStream>
#include<QFile>
int main()
{
QFile file("D://out.txt");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream out(&file);
out << "The magic number is: " << 49 << "\n";
}
To copy to clipboard, switch view to plain text mode
first I get the error:
..\filewrite\main.cpp:10: error: return-statement with no value, in function returning 'int'
If i comment out the if statement it runs but i don't create a file. i thought maybe i need to close the file first so i added file.close but that didn't do anything either.
Can someone please help!
Thanks
Matt
Bookmarks