I just need to write a string into a file created using ofstream, but I am getting an error.
This is the code:
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
QString aux = "Hello";
ofstream myfile ("test.txt");
if (myfile.is_open())
{
myfile << aux;
myfile.close();
}
else
{
cout << "CANT OPEN FILE";
}
return 0;
}
The error is: no match for 'operator<<' in 'myfile << aux'
P.S: I am using QT4
Thanks for your help!
You should convert to a string by doing : myfile << aux.toStdString(); This is because the << operator does not know any conversion from qt string.