Horje
string stream in c++ Code Example
string stream in c++
// CPP program to count words in a string
// using stringstream.
#include <bits/stdc++.h>
using namespace std;
  
int countWords(string str)
{
    // breaking input into word using string stream
    stringstream s(str); // Used for breaking words
    string word; // to store individual words
  
    int count = 0;
    while (s >> word)
        count++;
    return count;
}
  
// Driver code
int main()
{
    string s = "geeks for geeks geeks "
               "contribution placements";
    cout << " Number of words are: " << countWords(s);
    return 0;
}
how to parse using stringstream
#include <iostream>
#include <sstream>

std::string input = "abc,def,ghi";
std::istringstream ss(input);
std::string token;

while(std::getline(ss, token, ',')) {
    std::cout << token << '\n';
}




Cpp

Related
create vector of specific size c++ Code Example create vector of specific size c++ Code Example
executing an opencv c++ code Code Example executing an opencv c++ code Code Example
gcc suppress warning inline Code Example gcc suppress warning inline Code Example
c++ check if debug or release visual studio Code Example c++ check if debug or release visual studio Code Example
c++ find index of all occurrences in string Code Example c++ find index of all occurrences in string Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9