Search
 
SCRIPT & CODE EXAMPLE
 

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;
}
Comment

how to split string in c++

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

vector<string> string_burst(string str,char delimeter) 
{
  //condition: works with only single character delimeter, like $,_,space,etc.
    vector<string> words;
    int n=str.length();
    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 words;
}
Comment

how to split string into words c++

#include <string.h>

int main ()
{
  char str[] ="This is a sample string";
  char *p;
  
  p=strtok(str," ");
  while (p!= NULL)
  {
    cout<<p;
    p=strtok(NULL," ");
  }
  return 0;
}
Comment

split text c++

#include <boost/algorithm/string.hpp>

std::string text = "Let me split this into words";
std::vector<std::string> results;

boost::split(results, text, [](char c){return c == ' ';});
Comment

PREVIOUS NEXT
Code Example
Cpp :: stack overflow c++ 
Cpp :: c++ cout without include iostream 
Cpp :: how to find something in a string in c++ 
Cpp :: how to calculate bitwise xor c++ 
Cpp :: c detect os 
Cpp :: what is g++ and gcc 
Cpp :: new line in c++ 
Cpp :: error handling in c++ 
Cpp :: c++ base constructor 
Cpp :: c++ program to convert kelvin to fahrenheit 
Cpp :: how to use custom array in c++ 
Cpp :: getline 
Cpp :: inserting element in vector in C++ 
Cpp :: c++ finding gcd 
Cpp :: how to remove maximum number of characters in c++ cin,ignore 
Cpp :: getline() 
Cpp :: structure of a function in C++ 
Cpp :: convert all strings in vector to lowercase or uppercase c++ 
Cpp :: cpp linked list 
Cpp :: exponent of x using c c++ 
Cpp :: changing values of mat in opencv c++ 
Cpp :: long long int range c++ 
Cpp :: loop execution decending order in c 
Cpp :: how to reset linerenderer unity 
Cpp :: balanced parentheses 
Cpp :: minheap cpp stl 
Cpp :: inline function in cpp 
Cpp :: casting to a double in c++ 
Cpp :: c++ preprocessor commands 
Cpp :: c++ function pointer as variable 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =