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

mystring[0]

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

mystring[1]

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

mystring[0]

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

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.