|
-
September 2nd, 2011, 07:21 PM
#1
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.
-
September 2nd, 2011, 08:42 PM
#2
Re: How do I read text files?
-
September 3rd, 2011, 12:59 AM
#3
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.
-
September 3rd, 2011, 04:46 PM
#4
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
-
September 4th, 2011, 08:38 AM
#5
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++
-
September 4th, 2011, 12:15 PM
#6
Re: How do I read text files?
 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;
}
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
-
September 5th, 2011, 02:21 PM
#7
Re: How do I read text files?
 Originally Posted by monarch_dodra
Code:
#include <fstream>
int main()
{
std::ifstream myfile;
}
oh std::fstream thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|