forked from uufree/Linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit.cc
More file actions
41 lines (34 loc) · 1.07 KB
/
Copy pathsplit.cc
File metadata and controls
41 lines (34 loc) · 1.07 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
/*************************************************************************
> File Name: split.cc
> Author: uuchen
> Mail: 1319081676@qq.com
> Created Time: 2017年06月03日 星期六 14时31分33秒
************************************************************************/
#include<iostream>
#include<string>
#include<vector>
#include<time.h>
void split(const std::string& lhs,const std::string& rhs,std::vector<std::string>& vecStr)
{
size_t last = 0;
size_t index = lhs.find_first_of(rhs,last);
while(index != std::string::npos)
{
vecStr.push_back(lhs.substr(last,index-last));
last = index + 1;
index = lhs.find_first_of(rhs,last);
}
if((index-last) > 0)
vecStr.push_back(lhs.substr(last,index-last));
}
int main(int argc,char** argv)
{
std::vector<std::string> vec;
time_t Time = time(NULL);
std::string strTime = ctime(&Time);
std::cout << strTime << std::endl;
split(strTime," ",vec);
for(size_t i=0;i<vec.size();++i)
std::cout << i << " : " << vec[i] << std::endl;
return 0;
}