converting string first char to int

Hey guys, I've only recently started using C++ for university and I'm having trouble with one particular part of the code.
I'm trying to convert a particular part of the string into an integer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  #include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <string>
#include <time.h>
#include <errno.h>  
#include <math.h> 

using namespace std;


int main(int argc, char *argv[])

int num = atoi(argv[1]);
int base = atoi(argv[2][1]);


I have not included the rest of the code but the main focus is converting argv[2][1] into an integer without changing the main.

halp.
Last edited on
To convert a single character to an integer you can subtract '0'.
int base = argv[2][1] - '0'

Of course this will only work if the char is in the range '0'-'9'.
Topic archived. No new replies allowed.