Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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

stream in c++

#include <fstream>
Comment

PREVIOUS NEXT
Code Example
Cpp :: doubly linked list c++ code 
Cpp :: vector fin element c++ 
Cpp :: print each number of digit c++ 
Cpp :: C++ string initialization 
Cpp :: c++ initialize multidimensional vector 
Cpp :: c++ sieve of eratosthenes 
Cpp :: c++ get environment variable 
Cpp :: How to pause a c++ program. 
Cpp :: memcpy library cpp 
Cpp :: Parenthesis Checker using stack in c++ 
Cpp :: matrix transpose in c++ 
Cpp :: string to int c++ 
Cpp :: c++ clear char array 
Cpp :: append string cpp 
Cpp :: what is c++ used for 
Cpp :: priority queue c++ 
Cpp :: how to return char* from function in c++ 
Cpp :: c++ hello world 
Cpp :: who to include a library c++ 
Cpp :: C++ break with for loop 
Cpp :: vector find 
Cpp :: bubblesort c++ 
Cpp :: length of string in c++ 
Cpp :: c++ struct constructor 
Cpp :: c include 
Cpp :: insertion sort cpp 
Cpp :: length of array c++ 
Cpp :: inserting element in vector in C++ 
Cpp :: Give an algorithm for finding the ith-to-last node in a singly linked list in which the last node is indicated by a null next reference. 
Cpp :: initialize vector 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =