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 …
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 Postyes,but that is read one line.
how to jump to the second line?you can't "jump", file access is serial. if you need a certain position, read the first line(s) and discard it/them until you reach the position in the file that you need.
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 …
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.