Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-06-2005, 09:31 PM   #1
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 272

Rep: Reputation: 30
getline delimiter + move to next line?

Hey all,
First problem. I have a file, which i have declared:
 ofstream fout"filename",ios::app);
  assert (!;
i have done this so i can add data to the file. However i need to read data from the file first using getline and then write to the file. HOw can i read from the file with ofstream?????

I would like to use getline with a delimiter of ":" to read from this file.
Myfile looks like:
However. after i read to the first delimiter from the getline, i want to jump to the next line and skip the rest of the first line. Is this possible??

THank you very much.
Old 07-08-2005, 07:32 AM   #2
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
Ok... I'm a little rusty on common i/o here... but I'm pretty sure you want an fstream object for that file and not an ofstream object. ofstream is going to be write only.

Once you have read in a line, I'd throw it in a stl::string and use the methods stl::string has to easily parse through and get what you want... any questions on how to do this?
Old 07-08-2005, 04:38 PM   #3
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 272

Original Poster
Rep: Reputation: 30
ohh thanks, ill try the fstream, didnt think of that.

I have never heard of stl::string... nor do i completly understand how you think i can use it...
Can you please give me an example.

If i have a text file that i will use fstream to read and write from such as this

I want to be able to read to a certain delimiter (namely ":") get that data, and jump to the next line, and do the same.

Thanks so much!!!!!

Old 07-09-2005, 01:08 AM   #4
Senior Member
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 59
this is what i found
very straightforward on how to use it (the delimiter bit)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
c++ get() delimiter ashirazi Programming 3 08-06-2004 06:26 AM
getline hylke Programming 9 06-03-2004 02:24 PM
g++ and cin.getline() codeviking Programming 8 07-03-2003 08:42 AM
tab delimiter codename000 Programming 3 04-04-2003 11:18 AM
cin.getline adam_boz Programming 6 10-02-2002 09:57 AM

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

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