string and save it to another string please help!

so i'm trying get the user to input a date 12/05/2005 and the outcome will be Dec 05, 2005. i got the Dec part but after that im not sure what is the best way to get the other numbers without having "/" in it ? any idea guys?

example:
5/20/2016 ---> May 20, 2016
something like this!


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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>


using namespace std;
//Function prototype.


int main ()
{

  //asking user for info:
  const int size = 20;
  int date[size];
  int count = 0;

  int num;
  string data;
  cout << "asking user input: ";
  getline(cin, data);

  num = atoi(data.c_str());


  switch(atoi(data.c_str()))

  switch(atoi(data.c_str()))
{
  case 1:
    cout << "Jan";
    break;
  case 2:
    cout << "Feb";
    break;
  case 3:
    cout << "Mar" << endl;
    break;
  case 4:
    cout << "Apr";
    break;
  case 5:
    cout << "May";
    break;
  case 6:
    cout << "Jun";
    break;
  case 7:
    cout << "Jul";
    break;
  case 8:
    cout << "Aug";
    break;
  case 9:
    cout << "Sep";
    break;
  case 10:
    cout << "Oct";
   break;
  case 11:
    cout << "Nov";
    break;
  case 12:
    cout << "Dec";
    break;

  default:
    cout << "invalid input!" << endl;

 }


  return 0;

}

Last edited on
Couple suggestions, first it may be easier to have the input be 3 integers. If you are practicing using strings then I would recommend using std::string, in which case you can look through the string looking for the / and finding that to split up the string.

http://www.cplusplus.com/reference/string/string/
look up splitting a string by tokens
Topic archived. No new replies allowed.