The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.


Other UNIX.COM Threads You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read the file line by line kittusri9 Shell Programming and Scripting 3 04-24-2008 05:26 AM
How to read last line of a txt file? yongho UNIX for Dummies Questions & Answers 2 06-13-2005 10:20 AM
Read a file line by line VENC22 UNIX for Dummies Questions & Answers 2 05-12-2005 10:13 AM
read line from file rein Shell Programming and Scripting 5 04-14-2005 11:32 PM
How to read from a file line by line and do stuff spaceship Shell Programming and Scripting 4 03-17-2005 05:47 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-19-2008
Registered User
 

Join Date: Nov 2007
Posts: 108
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
How to read element of line of file

Hi,

I would like to get elements in data in a file.

My file data would be something like:-

foo 123.32 323 4356.234 22344.9
fon 234.454 3434 2362.3 34

...etc..

I would like to read the elements in this file each line by line and write onto another text file.

I am using getline to get these data from line by line basis. However, for element basis, I would like to use istream_iterator vector to store these values but im not sure how I could use that since vector only permits one type of data type. Instead, my data has mixture of string, float and ints data.

Another alternative im thinking would be using istringstream obj(line)

and then declare each element variable's data type before
obj>>a>>b>>c>>d>>e

But Im not too sure it is working or correct concept. Please help.

Thanks.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-20-2008
Registered User
 

Join Date: Jan 2008
Posts: 6
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
hi,

you can make use of stringtokenizer to help extract the values into "tokens". by default the delimiter to extract the value is "space" and also in this case all your values are seperated by space.

hope this helps.
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 06:07 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102