implementing split function in c++

void tokenize(string &str, char delim, vector<string> &out)
{
	size_t start;
	size_t end = 0;

	while ((start = str.find_first_not_of(delim, end)) != string::npos)
	{
		end = str.find(delim, start);
		out.push_back(str.substr(start, end - start));
	}
}

int main()
{
    string s="a;b;c";
    char d=';';
    vector<string> a;
    tokenize(s,d,a);
    for(auto it:a)  cout<<it<<" ";

    return 0;
}

3.7
10

                                    // splits a std::string into vector&lt;string&gt; at a delimiter
vector&lt;string&gt; split(string x, char delim = ' ')
{
    x += delim; //includes a delimiter at the end so last word is also read
    vector&lt;string&gt; splitted;
    string temp = &quot;&quot;;
    for (int i = 0; i &lt; x.length(); i++)
    {
        if (x[i] == delim)
        {
            splitted.push_back(temp); //store words in &quot;splitted&quot; vector
            temp = &quot;&quot;;
            i++;
        }
        temp += x[i];
    }
    return splitted;
}

3.7 (10 Votes)
0
4.5
2
Kay Bee 110 points

                                    std::string s = &quot;scott&gt;=tiger&gt;=mushroom&quot;;
std::string delimiter = &quot;&gt;=&quot;;

size_t pos = 0;
std::string token;
while ((pos = s.find(delimiter)) != std::string::npos) {
    token = s.substr(0, pos);
    std::cout &lt;&lt; token &lt;&lt; std::endl;
    s.erase(0, pos + delimiter.length());
}
std::cout &lt;&lt; s &lt;&lt; std::endl;

4.5 (2 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to separate string c++ string input and split in cpp str .split in c++ split string by a sequence delimiter c++ how to split string by delimiter in c++ split string at . in c++ c++ string split function string splitting in c++ split() in c++ splitting a string into substrings in c++ splitting a string into an array c++ how to split strings c++ seprate string by , in c++ how do i split a string in c++ how to split string based on delimiter c++ c++ parse a string with delimiter c++ split string delimiter c++ split string on / split a string cpp stringstream C++ string&gt; split split in c++ for string split string is c++ string splitter c++ what is the split function in C++ split string by separator c++ c++ why split declaration and definition c++ split string view by delimiter c++ string.split() split the string in cpp using stringstream how to split sting in c++ c++ string how to split split up string c++ c++ split line split string in cpp by cpp separate string by delimiter how to split a data with delimiter in c++ from text file split function in cpp .split in cpp c+ string split c++ split by &quot; &quot; split string in array c++ how split function work in the c++ split string by , c++ cpp split string by character cpp parse string delimiter string split function c++ split string in c++ how to split string array c++ how to split strings in a text file c++ how to do string splits in c++ split # in cpp c++ split strings c++ string method to split it implementing split function in c++ .split() in c++ split a string by a , cpp split a string cpp .split in c++ cpp array split c++ split splace c++ split equivalent array splitting c++ how to write split function in c++ split the string in cpp c++ read string with delimiter c++ split(*) how to use split function in c++ split string into array c++ how split a string from file in c++ string delimiter c++ spliting strings in cpp split string in c++ stl split string to array in c++ split line cpp how split file in c++ split function in c++ example string split in cpp stl split(/\s+/) split functionin c++ c++ split string at delimiter c++ split string with delimiter c++ split for string how to split strings in cpp split delimited c++ split delimiter c++ split in cpp strings c++ split array split C@+ how to create a split function in c++ break string with delimiter in cpp c++ split string on delimiter using getline split string array by delim c++ split method in c++ c++17 split string by delimiter C++ std::string split c++ split line with ; file split program in c++ cpp .split how to split string to character c++ splitting up a string in c++ hwo to split up a line on c++ c++ string splt delimiter function split en c++ using split function c++ using split in c++ split cpp string c++ split string to array by delimiter splitter c++ c++ how to include split c++ include split c++ string split to array string split in c++ std string split by delimiter std::string split c++ c++ string split by delimiter splite in cpp split method c++ split string by delimiter cpp how to split in c++ c++ split string by delimiter into list str split c++ c++ split on delimiter how to use split function in cpp split string i c++ string split c++ &quot;&gt;&gt;&quot; c++ split string by delimiter into string c++ string split into array how to split a string into separate strings c++ split in c++ stl c++ code splitting c++ split string by delimiter into array c++ split on - how to split strin in c++ how to split a string by delimiter in c++ splitting c++ string split function for strings in c++ c++ string.split how to split string in c++ by space string.split split up string in c++ split and store cpp string split delimiter c++ string c++ split splitting string element c++ cpp split and store c++ split_string documentation c++ string line split c++ line.split c++ string split on character std string c++ split c++ split by character how to split in in c++ split string with delimiter c++ split func in c++ c++ strings split string split in c++ stl c++ string split method how to split a string cpp split c++ at character string splitting c++ c++ split on character how to split strings at character c++ how to split a string in cpp split a string on , in c++ split string function c++ split string at character c++ c++ split by : split c++ reference split string based on delimiter c++ string cpp split SPLIT STRING in cPP split string into string array c++ split a string by + in cpp split array c++ c++ built in split function split in c++ string string .split in cpp split c++ function string split function in c++ string.split c++ c++ separate string by delimiter extract and split string c++ split at c++ how to separate a string in c++ c++ line split string spli in cpp c++ how to separate string line by separator split function in c++ how to cut a string in to parts in c++ pipe and colon separated string input in c++ split one string into two c++ c++ split string by token split string in C++ delimiter string splitter in c++ split in cpp string string parse cpp how to split an input in cpp how to separate string in c++ split string c++ by character string separator C++ split cpp how to split string into array in c++ how to separate a string c++ stl function to split string in c++ split array in c++ inbuilt c++ split string by character c++ string split. string split using delimiter in cpp c++ split String^ line.split() cpp c++ string format split c++ string split by character c++ split in string c++ split at period split slice c++ c++ get substring by delimiter s.split() in c++ get substring from string with delimiter c++ splitting a string in c++ parsing string c++ c++ split string by delimeter siplit string around another string c++ seperate a string in CPP how to chop up a string in c++ string .split c++ split text in c++ how to divide string in c++ split string using delimiter c++ split string into char c++ c++ function split string split string on character c++ split and join in cpp split string by token c++17 string split function cpp int(i) for i in input().split() IN C++ devide string in multiple parts cpp break a string with different delimiters c++ cpp split c++ split by char split stirng c++ equivalent of input().split() in c++ how to divide strings in c++ how to split the string in c++ split function c++ split string to string array by space c++ split(&quot; &quot;) string c++ split(0) c++ delimiter in cpp stl c++ strings split function split on char c++ how to split a string into 3 part c++ how to split the data in array in c++ by delimiter split a strign in c++ c++ split string by comma separate string by # c++ splitting string c++ c++ splitting a string with a delimiter c++ split string at character split methos C++ c++ split string on space c++ how to split string what is split in c++ is there a split for string in C++ split a string into two cpp c++ split string by char how to split the string and store the value in c++ c++ split string avec . c++ split string with . c++ split string by space making a split function in c++ how to ssplit string in cpp .split cpp splet string in c++ how we can split a string into two parts in cpp stl how to split stringin c++ separating a string c++ split line c++ c++ split by delimiter divide string c++ c++ split a string by string split copying in c++ c++ split string connected split string by token c++ string breaknig in c++ splitting line by delimiter cpp how to split std::string with delimiters in c++ like strtok c++ split row c++ string separate based on delimieter split string by spnce into array c++ c++ delimiter split a string with a delimiter in c++ input string and split in c++ split on '.' C++ how to split a string at every space in c++ String.Split in c++ split() function c++ how to do split on string c++ string split by , c++ how to split string using delimeter in c++ using sstream split lines in c++ split string on a character c++ splitting a string in cpp delimiter inC++ get information from a string with delimiters c++ c ++ string split split string c++ by delimiter c++ substring delimiter split a string in c+++ c++ split by , split() c++ string split at c++ parse string in c++ c++ split a string how to split string c++ split getline into tokens how to split a string based on delimiter in c++ split a string in cpp split in c++ parse string c++ split string with a string c++ how to split a string left and right in c++ how to divide the string between - in c++ how to divide the string with &quot;&quot; in c++ delimiter c++ how to split str in C++ c++ how to seperate a string .split() c++ breaking up a string in c++ parse a string using delimiter c++ parsing strings cpp how to split string in c++ C++ split() string partition c++ splitting the string in c++ parse through a string with delimiter c++ c++ split string up split string function in cpp delimiter token std how to split a string in c++ string partitin by , c++ spliting string in c++ split function in c++ string c++ delimiter string How do you split a string into parts? C++ split string by different token c++ how can i separate a string in c++ best way to splitn a line in c++ how too split a line in c++ how to split in string in C++ c/c++ parse string split in cpp character for delimiter c++ how to split a string in c++ with delimiter how split a string in C++ c++ split a string built in functions parse a string at delimete c++ how to use split in c++ how to split a string c++ how to seperate the words in a string in c++ c++ parse string split a string in c++ cpp split string on character cpp split string by delimiter split dot separated string C++ split word in cpp cpp split string how to split string cpp c++ split string in cout STRING parse c++ C++ splits method string c++ separator slit a string in cpp cpp seperate string into words how to parse a string in c++ std string split c++ 17 string parsing c++ 14 splitting when delimeter is char in c++ how to break a string with . in c++ delimiters c++ read in string delimeter c++ take input string and split in cpp c+ split string splitting string in c++ how to split a string at a certain character in c++ how to split a string by character in c++ delimitting string c++ getline as strsplit c++ Dividing in String C++ split in string c++ to split string using vector in c++ c++ break string according to delementer divide the string in 2 in c++ delimiter string c++ .split c++ function to separate words in c++ code to split a number string in C++ split funstion in c++ split string by delimiter c++ parsing string in C++ 14 split string in c++ split string char delimiter c++ split strings in cpp c++ split string by character into list how to split string in cpp split c++ string .spilt function in c++ c++ split function split string c++\ parsing a string c++ splitting words by string c++ cpp split strings how to split strings in c++ parse a string c++ how to parse STRING IN C++ cpp string split how to split the string in cpp parse string in cpp delimiter cpp c++ read string to delimiter parse a string in c++ c++ string split how to split a string c++ cpp how to split string c++ split split strings in c++ delim character c++ use split in c++ c++ store string separated by pipe string parsing c++ c++ how to split a string vector &lt;string&gt; split(const string &amp;) c++ working c++ breaking up string with delimeter c++ split string split string cpp c++ cplit strig str.split c++ delimiter and str.split c++ split a string c++ split std string by delimeter c++ split std string by delimiter string.split cpp c++ splitting a string string split c++ string split cpp split function for string in c++ siperating a string in c++ split c++ split string c++ c++ split string by delimiter string sepearate on delimiter c++ how to parse a line by delimeter in c++ split a string using delimiter in c++ c++ parse string basic how to break a string in c++ split a string based on a delimiter in c++
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source