-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.cpp
26 lines (24 loc) · 874 Bytes
/
util.cpp
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
#include "util.h"
// You can include any std header file here.
#include <regex>
using namespace std;
/**
* @brief split a string by the delimiter space aka ` ` and append the result to the back of the vector `ret`.
*
* @param s the string to be splitted
* @param ret result vector. In this lab, argument `ret` is a global variable
* and is used to store the words according to the appearance order.
*/
void split_string(const string& s, vector<string>& ret) {
// hint: you can use function `substr` to get a substring of the string `s`
// if you know what regular expression is, you can use `regex` to easily split the string `s`
// stringstream may be useful, too
// TODO: implement this function
/* Your code here */
stringstream ss(s);
string t;
while(ss>>t){
ret.push_back(t);
}
return;
}