Advertisement
Guest User

string help

a guest
May 1st, 2012
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. void readoriginaldate (string &);
  5. void breakoriginaldate(string, string&, string&, string&);
  6. int main()
  7. {
  8.     string originaldate, month, day, year;
  9.  
  10.     readoriginaldate(originaldate);
  11.     breakoriginaldate(originaldate, month, day, year);
  12.  
  13.  
  14.     return 0;
  15. }
  16.  
  17.  
  18. void readoriginaldate (string &origdate)
  19. {
  20.     int s;
  21.  
  22.     cout<<"Please enter the date in MM/DD/YY format, seperated by slashes."<<endl;
  23.     cout<<"For example, 6/11/08"<<endl;
  24.     getline(cin, origdate);
  25.  
  26.     s=origdate.size();
  27.     while (s>8||s<6){
  28.         cout<<"The date you have entered is invalid."<<endl;
  29.         cout<<"Please enter the date in MM/DD/YY format, seperated by slashes."<<endl;
  30.         cout<<"For example, 6/11/08"<<endl;
  31.         getline(cin, origdate);
  32.         s=origdate.size();
  33.     }
  34.  
  35.     cout<<origdate<<" is the original date"<<endl;
  36.     return;
  37. }
  38.  
  39.  
  40. void breakoriginaldate (string origdate, string &month, string &day, string &year)
  41. {
  42.     int slash;
  43.  
  44.     slash=origdate.find("/",0);
  45.     month=origdate.substr(0,slash);
  46.     cout<<month<<" is the month"<<endl;
  47.  
  48.     origdate.erase(0, slash);
  49.     slash=origdate.find("/",0);
  50.     day=origdate.substr(0,slash);
  51.     cout<<day<<" is the day"<<endl;
  52.  
  53.     origdate.erase(0, slash);
  54.     year=origdate;
  55.     cout<<year<<" is the year"<<endl;
  56.  
  57.     return;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement