Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

how to split a string into words c++

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    string str="23 156 1645 -2398 77";
    vector<string> words; 
    char delimeter=' ';
    int n=str.size();
    for(int i=0;i<n;i++)
    {
        int j=i;
        while(str[i]!=delimeter && i<n)
            i++;
        string temp=str.substr(j,i-j);
        words.push_back(temp);
    }    
    return 0;
}
 
PREVIOUS NEXT
Tagged: #split #string #words
ADD COMMENT
Topic
Name
4+7 =