Parse integers from string?

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

Join Date: Aug 2004
Posts: 48
Reputation: Coach_Nate is an unknown quantity at this point 
Solved Threads: 0
Coach_Nate's Avatar
Coach_Nate Coach_Nate is offline Offline
Light Poster

Parse integers from string?

 
0
  #1
Mar 6th, 2006
I was wondering if there is any way to parse integers from a string (like in java)? Anyone know of a built in function in c++?
Behind every great gymnast - is a mentally unstable coach.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,055
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: Parse integers from string?

 
3
  #2
Mar 6th, 2006
stringstream
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: Parse integers from string?

 
0
  #3
Mar 11th, 2006
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 5
Reputation: kawk is an unknown quantity at this point 
Solved Threads: 0
kawk's Avatar
kawk kawk is offline Offline
Newbie Poster

Re: Parse integers from string?

 
0
  #4
Mar 11th, 2006
atoi is a C function that works in C++.

e.g.:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4.  
  5. int main() {
  6. char s[80];
  7. int i;
  8. cin>>s;
  9. i = atoi(s);
  10. cout>>i;
  11. return 0;
  12. }

My C++ is a little rusty, but that's my example. Using the String class might be a little dirrerent.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: Parse integers from string?

 
0
  #5
Mar 11th, 2006
You mean string (lowercase 's').

atoi() is a non-standard function; if you have it, it would be in <cstdlib>.

If you insist on using C functions, see this link: http://faq.cprogramming.com/cgi-bin/...&id=1043284385
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: Parse integers from string?

 
0
  #6
Mar 11th, 2006
Rusty, indeed.
  1. cout>>i;
->
  1. cout<<i;
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,055
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: Parse integers from string?

 
2
  #7
Mar 11th, 2006
Originally Posted by dwks
atoi() is a non-standard function;
atoi is part of the C89 standard.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Parse integers from string?

 
0
  #8
Mar 11th, 2006
I wouldn't use atoi in c++, assuming of course _jsw's sources are correct

http://www.daniweb.com/techtalkforums/thread39691.html
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

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




Views: 15556 | Replies: 7
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC