Search
 
SCRIPT & CODE EXAMPLE
 

CPP

How to split a string by Specific Delimiter in C/C++

#include <bits/stdc++.h>
using namespace std;
 
void tokenize(string s, string del = " ")
{
    int start = 0;
    int end = s.find(del);
    while (end != -1) {
        cout << s.substr(start, end - start) << endl;
        start = end + del.size();
        end = s.find(del, start);
    }
    cout << s.substr(start, end - start);
}

int main(int argc, char const* argv[])
{
    // Takes C++ string with any separator
    string a = "Hi$%do$%you$%do$%!";
    tokenize(a, "$%");
    cout << endl;
 
    return 0;
}
Comment

split string by delimiter cpp

// C++ program to understand the use of getline() function
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    string S, T;
  
    getline(cin, S);
  
    stringstream X(S);
  
    while (getline(X, T, ' ')) {
        cout << T << endl;
    }
  
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to grab numbers from string in cpp 
Cpp :: take a function as an argument in c++ 
Cpp :: Fisher–Yates shuffle Algorithm c++ 
Cpp :: stack class implementation to file unix-style in c++ 
Cpp :: c++ check if key exists in map 
Cpp :: find positive number factorial in C++ 
Cpp :: how to empty a std vector 
Cpp :: fill two dimensional array c++ 
Cpp :: google test assert stdout 
Cpp :: max pooling in c++ 
Cpp :: c++ convert int to cstring 
Cpp :: min heap stl 
Cpp :: Initialize Vector Iterator Through Vector Using Iterators 
Cpp :: vector::at() || Finding element with given position using vector in C++ 
Cpp :: bubble sort c++ 
Cpp :: read a whole line from the input 
Cpp :: c++ online compiler 
Cpp :: assign one vector to another c++ 
Cpp :: unordered map c++ 
Cpp :: string c++ 
Cpp :: stl map remove item 
Cpp :: merge sort in descending order c++ 
Cpp :: C++ Vector Operation Change Elements 
Cpp :: malloc 2d array cpp 
Cpp :: An Array declaration by initializing elements in C++ 
Cpp :: C/C++ loop for 
Cpp :: string class in c++ 
Cpp :: Code debut C++ 
Cpp :: how does sorting array works in c++ 
Cpp :: C++14 (gcc 8.3) sample 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =