How do I read text files?
Hi I already found a tutorial on this but it didnt work. But I am wondering if anyone can tell me how to read text files line by line and determine what they say. Also is it posibble to make a new enumerated type but have it also be a function or class? Or would that cause errors?
Thanks ahead for helping.
Re: How do I read text files?
Re: How do I read text files?
very easy to do in QT ( a well developed C++ framework)
Code:
QFile myfile("text.txt");
myfile.open(QFile::ReadOnly);
QTextStream myreader(&myfile);
QString linereader = myreader.readline(); // reading one line at a time
Qstring readall = myreader.readall() // read all texty into a single QString same as std::string
if you are new to C++ then stick with well established framework as QT or wxwidgets
these frameworks make writing C++ code relatively easy and offer tons of easy to use API
further they are very well documented.
Re: How do I read text files?
I'd say qt is much better documented than wx. I'd also say for reading files stl is simple enough :)
Re: How do I read text files?
I just realised this might be in the wrong section but I use visual C++ for compiling c++ and it makes errors for the way I tried to do it. So how would I do it with that? It has an error where I
type:
ifstream myfile;
the error is "ifstream is unidentified"
So how would I do this on visual c++
Re: How do I read text files?
Quote:
Originally Posted by
HavingPhun
ifstream myfile;
the error is "ifstream is unidentified"
So how would I do this on visual c++
Code:
#include <fstream>
int main()
{
std::ifstream myfile;
}
Re: How do I read text files?
Quote:
Originally Posted by
monarch_dodra
Code:
#include <fstream>
int main()
{
std::ifstream myfile;
}
oh std::fstream thanks!