| | |
How do i fix this?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2005
Posts: 1
Reputation:
Solved Threads: 0
How do you convert a string to an int? In my book under string functions, it shows this short example:
which says that ia = 123.
So, I tried applying this to my code.
I included the <cstdlib> like the book says but i get this error message when I compiled it with the "CC" compiler:
what does this mean? how do i fix it? is there any other way to convert to an int?
C++ Syntax (Toggle Plain Text)
ia = atoi ("-123.45xyz");
which says that ia = 123.
So, I tried applying this to my code.
C++ Syntax (Toggle Plain Text)
index = atoi (a.GetCode()); cout<<description[index]; //a.GetCode() returns a number string 0 - 9 //description[] is an array that holds the job 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:
C++ Syntax (Toggle Plain Text)
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?
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
•
•
Join Date: Apr 2005
Posts: 63
Reputation:
Solved Threads: 1
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.
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.
![]() |
Similar Threads
- Windows XP keeps restarting since a new video card (Windows NT / 2000 / XP)
- Ad Aware will fix slow running Internet Explorer. (Web Browsers)
- Hijackthis Log: What to fix? (Viruses, Spyware and other Nasties)
- IE6 Hanging Up (on each new page) FIX! (Web Browsers)
- Fix Movie Interference in AVI Files (Windows tips 'n' tweaks)
- How can I fix an upgrade disaster? (Windows NT / 2000 / XP)
- What exactly does this error message mean and how can I fix? (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Hecadecimal
- Next Thread: please i need your help.
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






