954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Please help with atoi()

i'm trying to convert a string into an integer by using atoi() function. but it gives me an error:
error C2664: 'atoi' : cannot convert parameter 1 from 'class std::basic_string,class std::allocator >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

i've looked up how to use atoi() and i'm positive i'm using it right can someone offer some insight?

string b;
//b is given a value inbetween these two commands by way of
//a loop.
tree.Insert(atoi(b));


thanks for any help

LordJayno
Newbie Poster
6 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

atoi needs a pointer to a C-style string.

tree.Insert(atoi(b.c_str()));
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

thanks that worked great.

LordJayno
Newbie Poster
6 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You