Hi, I am having a user input a series of numbers and characters separated by spaces. like "10 23 65 34 765 34 65 34 64 354 64" and i need to put these into an array without the spaces. I stores them into a string but whenever i do like


i only get the first digit and not the number. or if i put


i only get the second number like in the digits above. i want


to contain 10 and not just 1.
Please help!!!!!!

8 Years
Discussion Span
Last Post by VernonDozier

The three functions that you need to look at are substr(), atoi(), and find(). All of these can be found here.
substr will create a string from say 0 to 1 and will hold "10" and then you use atoi() to convert "10" to 10 (integer) you might have to use .c_str() to convert your string to a cstring (const char*) inorder to use the atoi() function.
You can use the find() function to find the spaces in the string to do your substr() function.

Work out what you can and if you run into problems just post up your code I made a program a while ago for my friend that does exactly what you are looking for but I'm not going to hand it out with no code shown here.

PS the website I linked to is very good I would say. It is where I learned C++ and I use it often for reference. The tutorial section is here.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.