Results 1 to 2 of 2

Thread: Qt equivalent of C++ code

  1. #1
    Join Date
    Jun 2018
    Qt products

    Question Qt equivalent of C++ code

    I'm really new to Qt programming and still learning. I am looking for Qt equivalent of this code:
    Qt Code:
    1. #include <iostream>
    2. #include <string>
    3. #include <fstream>
    5. using namespace std;
    7. int main() {
    8. int i = 0;
    9. string name[3], age[3];
    10. ifstream FileRead("stu.txt");
    11. while(FileRead >> name[i] >> age[i]) {
    12. cout << name[i] << "\t" << age[i] << endl;
    13. i++;
    14. }
    15. FileRead.close();
    16. return 0;
    17. }
    To copy to clipboard, switch view to plain text mode 

    The main function of this code is that I want to read the file word by word and store the words into a particular array of strings.

    My file (stu.txt) contains the data:
    name1 age1
    name2 age2
    name3 age3
    and I want to store the "name1" into name[0] and "age1" into age[0].

    Is there an easy way I can do the same in Qt using QString, QFile etc?

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 818 Times in 807 Posts
    Qt products
    Windows Android

    Default Re: Qt equivalent of C++ code

    Yes. You will find very similar functionality in QString and QTextStream.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 3
    Last Post: 7th January 2017, 03:33
  2. cin Equivalent in Qt
    By amiref in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2011, 18:16
  3. QByteArray processing (seeking equivalent QT code)
    By pdoria in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2009, 09:40
  4. equivalent
    By deepa.selvaraj in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 18:33
  5. Qt-equivalent of pthread_once
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 15th October 2007, 21:57

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.