-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-join-using-delim.cpp
More file actions
62 lines (52 loc) · 1.09 KB
/
string-join-using-delim.cpp
File metadata and controls
62 lines (52 loc) · 1.09 KB
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
/* joining strings into one string by adding delimiter char
This can be used if we have directory list without /
ex:
input strings: C,Test,ABCD
Output string : C/Test/ABCD
*/
#include <vector>
#include <string>
#include <iostream>
using namespace std;
/*
int main()
{
vector<string> inputStr;
string out;
string delim = "/";
inputStr.push_back("C:");
inputStr.push_back("Test");
inputStr.push_back("ABC");
inputStr.push_back("Finalwarn");
for (auto ipst = inputStr.begin(); ipst != inputStr.end(); ipst++)
{
out+=*ipst;
if (ipst != inputStr.end()-1)
out+=delim;
}
cout<<out<<endl;
return 0;
}
*/
// We will convert above code in func
void joindelim(vector<string>& s, string& d, string& o)
{
for (auto ipst = s.begin(); ipst != s.end(); ipst++)
{
o+=*ipst;
if (ipst != s.end()-1)
o+=d;
}
}
int main()
{
vector<string> inputStr;
string out;
string delim = "/";
inputStr.push_back("C:");
inputStr.push_back("Test");
inputStr.push_back("ABC");
inputStr.push_back("Finalwarn");
joindelim(inputStr,delim,out);
cout<<out<<endl;
}