[ create a new paste ] login | about

Link: http://codepad.org/9IMCVVdx    [ raw code | output | fork ]

nadams - C++, pasted on Oct 31:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
using namespace std;

int convert(string & x, int digit = 0, size_t place = 0)
{
    if (place >= x.size())
        return 0;
    if (digit == 0)
        return x[x.size() - place - 1] - '0' + convert(x, 10, place + 1);
    else
        return (x[x.size() - place - 1] - '0') * digit + convert(x, digit * 10, place + 1);
}

int main()
{
    string x = "255";
    int z = convert(x);
    cout << z + 1 << endl;
}


Output:
1
256


Create a new paste based on this one


Comments: