Strings In Depth5 / 15
Up next

Parse a number

#include <print>
#include <string>

int main() {
    std::string text = "42";
    int n = std::stoi(text);
    double d = std::stod("3.14");
    std::println("{} {}", n + 1, d * 2);
}
What you're solving

std::stoi and std::stod convert text