The program I am writing is supposed to accept a social security number in the format ddd-dd-dddd.
My class textbook says that the format to index a specific character from a string is to use variable.at(index)
I used that format unsuccessfully. This is what DIDN'T work:
if ("-" == social.at(2) && "-" == social.at(5)){
It returns "Invalid operands to binary expression ('const std::string' (aka 'const basic_string') and 'std::basic_string::value_type' (aka 'char'))"
After researching previously-asked questions on here, I tried this on a whim, which works:
if ("-" == string(1, social[2]) && "-" == string(1, social[5])) {
However, I don't know what the difference between the two is. I am specifically confused by:
string(1,
Why is there a 1? Also, why did this work when the syntax I got from my textbook didn't? What method is this? Any help and resources are appreciated!