I have a string
string date="DD/MM/YYYY";
how do i get three numbers
day=atoi(DD);
month=atoi(MM);
year=atoi(YYYY);
thx
I have a string
string date="DD/MM/YYYY";
how do i get three numbers
day=atoi(DD);
month=atoi(MM);
year=atoi(YYYY);
thx
 
    
    int d=0, m=0, y=0;
sscanf(date.c_str(),"%d/%d/%d",&d,&m,&y); 
 
    
    Using a custom manipulator I'd do this
if (std::istringstream(date) >> std::noskipws
    >> day >> slash >> month >> slash >> year) {
    ...
}
The manipulator would look something like this:
std::istream& slash(std::istream& in) {
    if (in.peek() != '/') {
        in.setstate(std::ios_base::failbit);
    }
    return in;
}
 
    
    Or you can do it in this way,
int day = atoi(date.substr(0,2).c_str());
int month = atoi(date.substr(3,2).c_str());
int year = atoi(date.substr(6,4).c_str());
Using c_str() is because atoi takes char* and c_str() makes this.
