Opening a file to read and write to
-
Hi everyone,
So I'm trying to have my application be able to open a .txt file and read off a few lines of numbers. I have the txt file in the directory with all the .cpp and .h files but it won't open. I've added it to the project and so it is included in the .pro file. Any ideas? I can't figure out if its a necessitas issue or I'm just missing something super simple.@ifstream theFile;
theFile.open("highscores.txt", ios::in);
@I've tried different forms of the path too, w/ w/o "/" or the full path. Nothing has worked.
Thanks in advance.
-Doomberries -
Hi, ~Doomberries!
Welcome to Qt Developer Network!
It's better to use "QFile":http://qt-project.org/doc/qt-4.8/qfile.html class to work with files in Qt. Learn about it on the net. Just gugl it.
Code sample with QFile:
@
QFile file("highscores.txt");
if(!file.open(QIODevice::ReadWrite)) {
// impossible to open
} else {
// here you can read from file
}
@