Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualChad Smith

Posted 14 March 2013 - 08:19 PM

if you don't have c++11, no problem, you can use the atoi function.

 

It takes a c string as parameter returns an int, if you have a std::string just do

 

int myInt = atoi( myString.c_str() );

 

http://en.cppreference.com/w/cpp/string/byte/atoi

Yea I know, thanks though.  it's for both University Projects and to teach myself.  It had been a while since I've worked exclusively with C++ so I wanted to try to get myself used to working with std::stringstreams again.

 

Since you're using a stringstream you can just use rdbuf()->in_avail() after you extract the number. If in_avail() returns true, then there's stuff left in the buffer, which means that part of it didn't parse as a number. This assumes that you've already stripped out the whitespace anyways.

Thanks!  I'll have to do some quick research on that function!  I'll look into it now!

 

Thanks everyone!  Just wanted to learn some other and/or better ways to do some quick things.  Thanks for the suggestions!


#1Chad Smith

Posted 14 March 2013 - 08:15 PM

if you don't have c++11, no problem, you can use the atoi function.

 

It takes a c string as parameter returns an int, if you have a std::string just do

 

int myInt = atoi( myString.c_str() );

 

http://en.cppreference.com/w/cpp/string/byte/atoi

Yea I know, thanks though.  it's for both University Projects and to teach myself.  It had been a while since I've worked exclusively with C++ so I wanted to try to get myself used to working with std::stringstreams again.


PARTNERS