Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,021 questions

51,968 answers

573 users

How to tokenize a string in C++

2 Answers

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

int main()
{
    string s = "c++ c java php";
    vector <string> tokens; 
      
    stringstream sst(s); 
      
    string word; 
      
    while(getline(sst, word, ' ')) { 
        tokens.push_back(word); 
    } 
      
    for(int i = 0; i < tokens.size(); i++) {
        cout << tokens[i] << endl; 
    } 
    
    return 0;
}


/*
run:

c++
c
java
php

*/

 



answered Dec 5, 2019 by avibootz
0 votes
#include <bits/stdc++.h> 
    
using namespace std;

int main()
{
    string s = "c++ c java php";

    stringstream sst(s); 
      
    string token; 
      
    while(getline(sst, token, ' ')) { 
        cout << token << endl; 
    } 

    return 0;
}



/*
run:

c++
c
java
php

*/

 



answered Dec 5, 2019 by avibootz

Related questions

1 answer 99 views
99 views asked Apr 10, 2025 by avibootz
1 answer 411 views
411 views asked Dec 5, 2019 by avibootz
1 answer 154 views
3 answers 308 views
...