Hyphens in program..??

Does anyone know how I'd go about adding hyphens to this program when typing in a social security #..? I got the sample run up but dont really know where to start to put that type of function to tell the program to do that..?? Here it is..:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Social Security Number.cpp
// displays the Social Security number with hyphens
// Created/revised by <YOUR NAME> on <current date>
// string commands used:
//    getline(), length(), insert()
/* Sample Program Run
Social Security number without hyphens: 123456789
Social Security number: 123-45-6789
*/

#include <iostream>
#include <string>
using namespace std;

int main()
{
   // declarations
   string ssn = "";

   // statements
   cout << "Social Security number without hyphens: ";
   getline(cin, ssn);

   if (ssn.length() == 9)
   {
      //insert hyphens
      // STUDENT CODE BEGINS



      // STUDENT CODE ENDS
      cout << "Social Security number: " << ssn << endl;
   }
   else
      cout << "The number must contain "
           << "9 characters" << endl;
   //end if

   cin.get();
   return 0;
}  //end of main function 
I tried using this in my student code but still left with 3 errors.../:

 
string ssn = ssn.Insert(5, "-").Insert(3, "-");
Remember that C++ is case sensitive.
This should work:
ssn.insert(5, "-").insert(3, "-");
so its compiling with no errors but for some reason now its giving me some debug error because of an invalid allocation...?? Any ideas to why this is..??
You didn't change anything else, did you?
No I didnt...saying something about the bytes size.../: wants me to debug it for some reason...
NVM..! switched it up a bit and got it to work now...thank you sir...
Topic archived. No new replies allowed.