confused with istringstream
hello im trying to validate a social number with istrigstream
my program works great but i'm a little confused why it works heres the code:
confution explained later...
Code:
#include <iostream>
using namespace std;
#include <string>
using std::string;
#include <sstream>
using std::istringstream;
bool validate(istringstream &);
int main()
{
string sNumber("111-22-3333");
istringstream innString(sNumber);
if(validate(innString))
cout << "\nValid social number";
else
cout << "\nWrong social number";
cout << endl;
return 0;
}
bool validate(istringstream &innNumber)
{
int p1;
int p2;
int p3;
char char1;
char char2;
if(innNumber >> p1 >> char1 >> p2 >> char2 >> p3)
return true;
else
return false;
}
if you see the social number is not separated by blank spaces, how the istringstream knows that the first "111" must be in p1
how knows that '-' must be in char1, etc?
when the string is separated by blank spaces and you use >>
it discharges the spaces and thats fine. but here i dont have any
space, how this works?
or in other words how knows when it is an int and when is a char? if theres no blank spaces?
please any help?
and excuse my poor english