在 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP