How can I read a text file line by line in Qt?
I'm looking for the Qt equivalent to:
std::ifstream infile; std::string line; while (std::getline(infile, line)) { ... }
std::ifstream infile; std::string line; while (std::getline(infile, line)) { ... }
Your current working folder is set by Qt Creator. Go to Projects >> Your selected build >> Press the 'Run' button (next to 'Build) and you will see what it is on this page which of course you can change as well. Show activity on this post. It can happen that the cause is not that you don't find the right directory.
Use this code:
QFile inputFile(fileName); if (inputFile.open(QIODevice::ReadOnly)) { QTextStream in(&inputFile); while (!in.atEnd()) { QString line = in.readLine(); ... } inputFile.close(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With