LinuxQuestions.org
Register a domain and help support LQ
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 07-06-2005, 08:31 PM   #1
blizunt7
Member
 
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:
Code:
 ofstream fout
  fout.open("filename",ios::app);
  assert (!fout.fail());
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?????

second:
I would like to use getline with a delimiter of ":" to read from this file.
Myfile looks like:
Code:
4000:name:data:otherstuff
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.
Josh
 
Old 07-08-2005, 06:32 AM   #2
jtshaw
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, 03:38 PM   #3
blizunt7
Member
 
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

Code:
number:data:name:address
number:data:name:address
....
.....
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!!!!!

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

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


Reply


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


All times are GMT -5. The time now is 07:25 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration