Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Split the sentence into words in C++
Given is the task to split the sentence into words. In this, we will separate all the words present in sentence.
Input
I am a good boy
Output
I am a good boy
In the above example we will print the single word in single line.
Example
#include<iostream.h>
#include<string.h>
#include<stdio.h>
Using namespace std;
void split( string st){
String word = “ “;
for ( char s : st){
If (s== ‘ ‘){
Cout<< z << endl;
z = “ “;
}
else{
z = z = s;
}
}
Cout<< z <<endl;
}
Int main( ){
String st = “ Blood from heaven is mortal”;
Cout<< “Blood from heaven is mortal”;
Split(st);
return 0;
}
Output
If we run the above code it will generate the following output
Blood from heaven is mortal Blood From Heaven is mortal
Example
#include
#include
#include
Using namespace std;
Void split( string st){
String word = “ “;
for ( char s : st){
If (s== ‘ ‘){
Cout<< z << endl;
z = “ “;
}
else{
z = z = s;
}
}
Cout<< z <<
}
int main( ){
String st = “ type a text message”;
Cout<< “type a text message”;
Split(st);
return 0;
}
Output
If we run the above code it will generate the following output
type a text message type a text message
Advertisements