Answers for "c++ separate string by \n"

C++
4

c++ split at character

std::stringstream test("this_is_a_test_string");
std::string segment;
std::vector<std::string> seglist;

while(std::getline(test, segment, '_'))
{
   seglist.push_back(segment); //Spit string at '_' character
}
Posted by: Guest on February-26-2020
0

c ++ splitlines

std::vector<std::string> split_string_by_newline(const std::string& str)
{
    auto result = std::vector<std::string>{};
    auto ss = std::stringstream{str};

    for (std::string line; std::getline(ss, line, 'n');)
        result.push_back(line);

    return result;
}
Posted by: Guest on August-12-2021

Code answers related to "c++ separate string by \n"

Browse Popular Code Answers by Language