rgcomm
asked on
string to int
What am I doing wrong?
#include <string>
#include <iostream>
#include <stdlib.h>
using namespace std;
string strt0 = "1234567890";
string strt1 = str0.substr(4,2);
int strt2 = atoi(strt1);
error C2664: 'atoi' : cannot convert parameter 1 from 'class std::basic_string<char,str uct std::char_traits<char>,cla ss std::allocator<char> >' to 'const char *'
#include <string>
#include <iostream>
#include <stdlib.h>
using namespace std;
string strt0 = "1234567890";
string strt1 = str0.substr(4,2);
int strt2 = atoi(strt1);
error C2664: 'atoi' : cannot convert parameter 1 from 'class std::basic_string<char,str
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To elaborate - the compiler is right to complain about a 'string' data type when 'char*' is expected. The STL 'string' doesn't havea 'by-default' conversion as e.g. the MFC 'CString' class has...
ASKER
Thank you very much!