"Mike Vallely" <mk*************@hotmail.com> wrote in message

news:HU******************@newssvr31.news.prodigy.c om...

If anyone could help me with my problem I'd greatly appreciate it, this

question probably has a quick easy answer but I've been wanting to punch
the wall for the last hour because of it.

I have a string IDNUM = "12345";

I need to do simple arithmetic with the integers in this string.

The way I've been trying and failing is by doing something similar to
this:

int x , y;

string i1=IDNUM.substr(0,1); //sets i1 = 1 hopefully

x = atoi(i1); //Here, I fail to convert the integer in the string to

the type integer

y = x + 5;

I know the "x = atoi(i1)" is the root of all of my problems. But I do not

know how to fix it, and I have two books both of which do not touch on

atoi( ) at all. (buying a new book right now isn't the most convenient

option). At the time this section of code executes, the integers in the

string could be anything, so I can't just plug in the numbers.

So to sum up my question, I have a string of integers named IDNUM, and I

cannot figure out how to use the integers in this string outside of

outputting the string and then having the user re-enter the numbers they
see into an INT variable, which is stupid. Thanks in advance for any help.

-Mike V

The root of the problem is that you don't know how to use string.

string str = "12345";

int x = atoi(str.c_str());