Yep! Another question from Me!

Yes, I do have another question. I am working on a big program that I need lots of help with.

Is there any way to extract a number from a string and store it in an integer? I have already googled it to my best attempt.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <cstdlib>
#include <iostream>
#include <sstream>
using namespace std;

int main() {
    // Using atoi
    int i = atoi("123");
    cout <<  "i == " << i << endl; // prints "i == 123"

    // Using stringstream
    stringstream ss("10 20 30");
    int a, b, c;
    ss >> a >> b >> c;
    cout << "a, b, c == " << a << ", " << b << ", " << c << endl; // prints "a, b, c == 10, 20, 30"
}
Last edited on
Topic archived. No new replies allowed.