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 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 :: c++ length of char* 
Cpp :: how to find length of character array in c++ 
Cpp :: how to string to integer in c++ 
Cpp :: character array to string c++ stl 
Cpp :: c++ char to uppercase 
Cpp :: latex double subscript 
Cpp :: c++ check if char is number 
Cpp :: how to do nCr in c++ 
Cpp :: iterating in map/unordered map c++ 
Cpp :: substring to int c++ 
Cpp :: how to install boost c++ on windows 
Cpp :: c++ iterate map 
Cpp :: number of words in c++ files 
Cpp :: if vector is empty c++ 
Cpp :: vector.find() 
Cpp :: for loop in c++ 
Cpp :: string to decimal c++ strtol 
Cpp :: minimum value in array using c++ 
Cpp :: convert string to lpwstr 
Cpp :: C++ break and continue 
Cpp :: struct and pointer c++ 
Cpp :: c++ remove text file 
Cpp :: c++ keyboard input 
Cpp :: factorial function c++ 
Cpp :: c++ modulo positive 
Cpp :: sina + sinb formula 
Cpp :: how to square a number in c++ 
Cpp :: arduino xor checksum 
Cpp :: c++ cout without include iostream 
Cpp :: intersection.cpp 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =