We are going to share a C++ program to split a sentence into words and print words. If you are a beginner and want to start learning the C programming, then keep your close attention in this tutorial as I am going to share a program for C++ program to split a sentence into words and print words.
We believe you have a basic knowledge of c++ programming language.
In the following c++ program, we have created a custom removeDupWord()
function to remove duplicate words from the given string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <bits/stdc++.h> using namespace std; void removeDupWord(string str) { string word = ""; for (auto x : str) { if (x == ' ') { cout << word << endl; word = ""; } else { word = word + x; } } cout << word << endl; } // Program entry int main() { string str = "Free Web Mentor"; removeDupWord(str); return 0; } |
Free
Web
Mentor
Liked this program? Do Like & share with your friends.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.