Given a string containing space-separated words and a number K. The task is to find and print all those words whose length is greater than K using stringstream in C++.
A general solution to solve this problem using loops is discussed in the previous article. In this article, a solution using stringstream in C++ will be discussed.
Input : str = "hello geeks for geeks is computer science portal" K = 4 Output : hello geeks geeks computer science portal Input : str = "string is fun in python" K = 3 Output : string python
The idea is to use stringstream to create a stream by splitting the given string into tokens and then process the stream and print the words with length greater than K.
Below is the implementation of the above idea:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.