Link to home
Start Free TrialLog in
Avatar of rgcomm
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,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...
Avatar of rgcomm
rgcomm

ASKER

Thank you very much!