convert std::string to const char*

how can i convert std::string to const char* so i can use it with the atoi(); function to convert the sub-string to integer
Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  #include<iostream>
  #include<string>
  using std::string;
  int main()
   {
    string member="3x^5";
     size_t start_var=member.find_first_not_of("123456789-+");
    size_t end_var=member.find_first_of('^');
     string variable=member.substr(start,end-start);
     int var=atoi(variable);
   

    return 0;
   }
You can use the c_str() member function.
http://www.cplusplus.com/reference/string/string/c_str/

Or you could use std::stoi or std::istringstream instead of atoi and not have to convert it to const char*.
Topic archived. No new replies allowed.