Sign in to follow this  
Whelzorn

question on character arrays

Recommended Posts

I am having a bit of a problem here. What I need to do is turn a character array storing numbers and characters (such as an array containing "12-06 89") into an integer, but only for the first 2 characters. so out of the character array "12-06 89" I want integer m to store the first two characters as an integer value of 12. Is this possible? by the way, I am using C++. Thank you, Justin

Share this post


Link to post
Share on other sites
that ignore(); isn't even necessary, integer reading is stopped when a non integer character is encountered (in fact all non-number characters are non-int, but with float, if there is a '.' character, the float value is correctly read)

Share this post


Link to post
Share on other sites
That's true, but the delimiting character is not discarded. If you did not call ignore(), the next number read in would be -6, and I'm assuming that Whelzorn wants it to be +6, not -6.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this