在 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