String To Int C++

Source URL:

Language: cpp

Created on: 2020-07-28 13:37:48

#include <iostream>
#include <string>

int main() {

    std::string str = "123";
    int num;

    // using stoi() to store the value of str1 to x
    num = std::stoi(str);

    std::cout << num;

    return 0;
In this tutorial, we will learn how to convert string to int and vice versa with the help of examples.