extracting data from a string

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2007
Posts: 35
Reputation: RohitSahni is an unknown quantity at this point 
Solved Threads: 0
RohitSahni RohitSahni is offline Offline
Light Poster

extracting data from a string

 
0
  #1
Nov 10th, 2008
001 00002 0000003 00004 000005 6 000007 008009
------------------------------------------------------------------------------------------------------
GBL UTG.L 0692861 DCGB 000000 0 205750 826UTG
GBL UU.L 0646233 DCGB 000000 0 722501 -371UU.

I have the above data line by line each and coloumn has fixed width then in those i want to assign 9 coloumns to variables reading each line at a time.
Can you pleae help me how the indexing of this is possible in C++.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: extracting data from a string

 
0
  #2
Nov 10th, 2008
Originally Posted by RohitSahni View Post
001 00002 0000003 00004 000005 6 000007 008009
------------------------------------------------------------------------------------------------------
GBL UTG.L 0692861 DCGB 000000 0 205750 826UTG
GBL UU.L 0646233 DCGB 000000 0 722501 -371UU.

I have the above data line by line each and coloumn has fixed width then in those i want to assign 9 coloumns to variables reading each line at a time.
Can you pleae help me how the indexing of this is possible in C++.
Use std::getline(std::iostream&,std::string) function to get data line by line and substr(initial_pos,field_width) std::string member function to extract data fields. Don't forget: starting pos is eq to 0...

I see only 8 columns in your example...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC