I'm trying to figure out how to use the atoi function I have wrote and understand this so far:
#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
int x;
string str="34";
x=atoi(str);
cout<<x;
system("pause");
return 0;
}
And Then I get error reports about a freakin const char?! HELP!
CPPRULZ
0
Junior Poster in Training
Recommended Answers
Jump to Postthe string::c_str() method converts the contents of an std::string to const char*. For example:
string str1 = "Hello"; const char* str2 = "Hello"; str1.c_str();//would return a value equivalent to str2
You'd be better off using string streams though. there isn't …
All 4 Replies
CoolGamer48
65
Posting Pro in Training
CPPRULZ
0
Junior Poster in Training
CoolGamer48
65
Posting Pro in Training
Salem
commented:
Say yes to string streams, no to atoi
+20
CPPRULZ
0
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.