LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-06-2011, 09:13 AM   #1
lalhad21
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Rep: Reputation: 0
Store line from text file into list C++


Hello,

I'm wondering how it is possible to read each line from a text file, and then store each line separately in a list, using C++?

Thanks
 
Old 02-06-2011, 09:59 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,223

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Use an ifstream to read into a vector of strings.

That should be enough keywords to start you off.
 
Old 02-06-2011, 10:30 AM   #3
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
You can use a map too to store the line number and
the corresponding line. That way you can fetch/erase a line
according to the given line number without having to traverse
through for loops!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep query to list 1 line [which is fixed] and the next line after it [variable text] Glenn D. Linux - Software 3 01-20-2011 06:21 AM
Cannot read text from text file and store it in a variable using shell script anurupr Linux - Newbie 2 03-03-2010 01:38 PM
How to read in line-by-line from a file and store them in several variables ncjlee Programming 1 09-28-2008 06:20 PM
How to store text(strings) in a 2D character array reading from a text file(C++) bewidankit Programming 3 02-14-2008 07:08 AM
Bash store last line from displayed text output in a variable carl0ski Programming 1 01-16-2007 03:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration