用C ++将句子拆分成单词
将句子分解为单词的任务是给定的。在这里,我们将句子中出现的所有单词分开。
输入值
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
热门推荐
3 怎么说祝福语简短
10 古诗生日祝福语简短独特
11 祝福语怎么写大全简短
12 公司开年仪式祝福语简短
13 药店祝福语简短10字
14 酒桌升学祝福语简短
15 群里祝福语简短幽默
16 高考送考祝福语简短
17 六十岁大寿祝福语简短
18 简短长辈新年祝福语