Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Opening a file to read and write to

    Mobile and Embedded
    2
    2
    1489
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      Doomberries last edited by

      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

      1 Reply Last reply Reply Quote 0
      • T
        tucnak last edited by

        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
        }
        @

        1 Reply Last reply Reply Quote 0
        • First post
          Last post