Please help with atoi()

Reply

Join Date: Oct 2005
Posts: 6
Reputation: LordJayno is an unknown quantity at this point 
Solved Threads: 0
LordJayno LordJayno is offline Offline
Newbie Poster

Please help with atoi()

 
0
  #1
Nov 14th, 2005
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<char,struct std::char_traits<char>,class std::allocator<char> >' 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?

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

thanks for any help
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,361
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 241
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Please help with atoi()

 
0
  #2
Nov 14th, 2005
atoi needs a pointer to a C-style string.
  1. tree.Insert(atoi(b.c_str()));
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 6
Reputation: LordJayno is an unknown quantity at this point 
Solved Threads: 0
LordJayno LordJayno is offline Offline
Newbie Poster

Re: Please help with atoi()

 
0
  #3
Nov 14th, 2005
thanks that worked great.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC