In C++, the case matters. If you declare your string as s
, you need to use s
, not S
when calling it. You are also missing a semicolon to mark the end of the instruction. On top of that, the atoi
takes char *
as parameter not a string, so you need to pass in an array of char or a pointer to a char array:
Function signature: int atoi (const char * str);
string s = "453"; // Missing ';'
int y = atoi(s.c_str()); // Need to use s, not S
Full code:
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
void main() // Get rid of the semicolon here
{
string s = "453"; // Missing ';'
int y = atoi(s.c_str()); // Need to use s, not S
cout << "y =\n";
cout << y;
char e; // This and the below line is just to hold the
// program and avoid the window/program to
// close until you press one key.
cin >> e;
}