c 2b 2b splitlines

Solutions on MaxInterview for c 2b 2b splitlines by the best coders in the world

showing results for - "c 2b 2b splitlines"
Erika
11 Aug 2018
1std::vector<std::string> split_string_by_newline(const std::string& str)
2{
3    auto result = std::vector<std::string>{};
4    auto ss = std::stringstream{str};
5
6    for (std::string line; std::getline(ss, line, '\n');)
7        result.push_back(line);
8
9    return result;
10}
11
Alessandra
10 May 2016
1std::vector<std::string> Loader::StringToLines(std::string string)
2{
3    std::vector<std::string> result;
4    std::string temp;
5    int markbegin = 0;
6    int markend = 0;
7
8    for (int i = 0; i < string.length(); ++i) {     
9        if (string[i] == '\n') {
10            markend = i;
11            result.push_back(string.substr(markbegin, markend - markbegin));
12            markbegin = (i + 1);
13        }
14    }
15    return result;
16}
17