split a string array by delimiter

we have an string array A {12/23/34/45/456/565/.....}
that the user is going to enter then we want to split it by "/" into another array called date1 !

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  string date1[100];
	int e=0;
  for(int i=0; i<A[e].length();i++)
  
	 { if( Date[i]!="/")
		  date1[i]+=Date[e];
	  else
		  e++;}
  
  for(int i=0; i<e+1;i++)
	{  cout<<date1[i]<<endl;
  }



I want the output arrays elements to be
12
23
34
....
Have you tried using a stringstream and getline() with the optional third parameter (the delimiter) to process the first string?

1
2
3
4
5
6
7
8
9
10
...
    stringstream sin(A);
    string temp;
    vector<string> date1;
    while(getline(sin, temp, '/'))
        date1.push_back(temp);

    for(auto& itr : date1)
        cout << itr << endl;
...


This is the same advice as you have already received from your other topic: http://www.cplusplus.com/forum/beginner/190184/
Last edited on
Thank You we will check it
Topic archived. No new replies allowed.