Hey guys, sorry I am asking so many questions lately, but I am learning this stuff by myself, and find it easier to ask questions here than look online. Plus when I try using the search engine on this site, it takes me to some quite random threads.

Anyhow, onto the question: How do I read a 'line', not a word from a text file? (I am guessing it has something to do with the getline function?)

Recommended Answers

All 4 Replies

If you look at the function getline , you can see that it's first argument is of the type "istream&". In the example provided in the link, cin is used, but this can also be a stream to an inputfile.

If you look at the function getline , you can see that it's first argument is of the type "istream&". In the example provided in the link, cin is used, but this can also be a stream to an inputfile.

Yes, I am fairly familiar with the getline function, but not so much with getting a line from a text file.

Yes, I am fairly familiar with the getline function, but not so much with getting a line from a text file.

Do you have a problem with tutorials, text books, and Google? That is where you do the first level of learning. We are here to fine tune what you failed to understand. We are not teachers.

Your question is a first level question. Look it up. Try it out. When it doesn't work, that's where we come in...

I hope i answer your question right... "How do I read a 'line', not a word from a text file?"

There needs more to this code, just a base outline of getline.

#include <string>     // library that can is used

string ____;   //delcare varible name

getline(fstream name, string name);

the underline is for what you named your sting.

I hope this makes sense!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.