-1

i have been trying to make a program that checks if a national identification number is valid how ever i have run into a issue and i can't find an answer anywhere. I am using a string to store the users input of the identification code and i need to somehow covert the string to int keeping the symbol instead of getting an ascii value.

Example: (lets say the user inputs the string persKods as 111199-11111 the 5th symbol is 9 so the year value should output as 9 instead of 54 which is its ascii value)

int day,month,year;
year=this->persKods.at(4);
cout << year; // it outputs 54 instead of 9 :/

1 Answers1

1

Can you try to ascci value of '0'.

#include <iostream>
using namespace std;

int main() {
    // your code goes here
    string str="111199";
    int test = str.at(4) - '0';

    cout<<test;

    return 0;
}

For more information link

Naruto
  • 653
  • 8
  • 19