if I have three words in there lines in a .txt file, and I want to read them to three string, how to do this using c++ ifstream? how to read every line(word)?
linq 0 Light Poster
Recommended Answers
Jump to PostReading from a file works the same way as reading from any other istream, such as cin:
//read up to newline std::string str; std::getline(cin, str);
//read up to whitespace (after a word or character) std::string str; cin >> str;
With files, replace cin with the name of …
Jump to PostI just want to ask how to reach the position which I want
Just repeat the code Bench posted until you get to the desired line. You will have to use a loop and a counter integer to keep track of the line number that was just read. If you …
Jump to Postbut how to use pointer to move the reading postion? point to what?
Looks like you need some code right? Otherwise you're just going to be going around in circles?
Jump to Postis he/she looking for the 3rd word or line?
All 15 Replies
Bench 212 Posting Pro
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
linq 0 Light Poster
Bench 212 Posting Pro
linq 0 Light Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
linq 0 Light Poster

iamthwee
Bench 212 Posting Pro

iamthwee
linq 0 Light Poster

iamthwee
Bench 212 Posting Pro
linq 0 Light Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
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.