I'm really new to Qt programming and still learning. I am looking for Qt equivalent of this code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
int i = 0;
string name[3], age[3];
ifstream FileRead("stu.txt");
while(FileRead >> name[i] >> age[i]) {
cout << name[i] << "\t" << age[i] << endl;
i++;
}
FileRead.close();
return 0;
}
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
int i = 0;
string name[3], age[3];
ifstream FileRead("stu.txt");
while(FileRead >> name[i] >> age[i]) {
cout << name[i] << "\t" << age[i] << endl;
i++;
}
FileRead.close();
return 0;
}
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?
Bookmarks