How do i fix this?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2005
Posts: 1
Reputation: gracieLou is an unknown quantity at this point 
Solved Threads: 0
gracieLou gracieLou is offline Offline
Newbie Poster

How do i fix this?

 
0
  #1
Apr 3rd, 2005
How do you convert a string to an int? In my book under string functions, it shows this short example:

  1. ia = atoi ("-123.45xyz");

which says that ia = 123.

So, I tried applying this to my code.
  1. index = atoi (a.GetCode());
  2. cout<<description[index];
  3.  
  4. //a.GetCode() returns a number string 0 - 9
  5. //description[] is an array that holds the job
  6. descriptions to the corresponding code

I included the <cstdlib> like the book says but i get this error message when I compiled it with the "CC" compiler:

  1. Error: Could not find a match for std::atoi(std::basic_string<char, std::char_traits<char>, std::allocator<char>>)

what does this mean? how do i fix it? is there any other way to convert to an int?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,341
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: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: How do i fix this?

 
0
  #2
Apr 3rd, 2005
You may want to look up strtod or strto[u]l. If you are trying to use these C-style functions with a std::string, look at the c_str() member function too.
"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: Apr 2005
Posts: 63
Reputation: marinme is an unknown quantity at this point 
Solved Threads: 1
marinme marinme is offline Offline
Junior Poster in Training

Re: How do i fix this?

 
0
  #3
Apr 4th, 2005
I think that your problem is you are trying to pass a string object to the atoi function.

the way that your book uses it is atoi(char *) using a C-style string, not a string object. I'm not sure if it does have an overloaded version using the string object. What you could do is just have your function return yourString.c_str() and it should work.
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC