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
}
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
}
implementing split function in c++
// splits a std::string into vector<string> at a delimiter
vector<string> split(string x, char delim = ' ')
{
x += delim; //includes a delimiter at the end so last word is also read
vector<string> splitted;
string temp = "";
for (int i = 0; i < x.length(); i++)
{
if (x[i] == delim)
{
splitted.push_back(temp); //store words in "splitted" vector
temp = "";
i++;
}
temp += x[i];
}
return splitted;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us