वाक्य को शब्दों में विभाजित करने का कार्य दिया गया है। इसमें हम वाक्य में उपस्थित सभी शब्दों को अलग कर देंगे।
इनपुट
I am a good boy
आउटपुट
I am a good boy
ऊपर के उदाहरण में हम सिंगल वर्ड को सिंगल लाइन में प्रिंट करेंगे।
उदाहरण
#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;
} आउटपुट
यदि हम उपरोक्त कोड चलाते हैं तो यह निम्न आउटपुट उत्पन्न करेगा
Blood from heaven is mortal Blood From Heaven is mortal
उदाहरण
#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;
} आउटपुट
यदि हम उपरोक्त कोड चलाते हैं तो यह निम्न आउटपुट उत्पन्न करेगा
type a text message type a text message