দেওয়া হয়েছে একটি সেন্টেন্সকে ওয়ার্ডে ভাগ করার টাস্ক। এখানে আমরা সেন্টেন্সে থাকা সব ওয়ার্ড আলাদা করব।
ইনপুট
I am a good boy
আউটপুট
I am a good boy
উপরের উদাহরণে প্রতিটি ওয়ার্ডকে আলাদা লাইনে প্রিন্ট করা হয়েছে।
উদাহরণ ১
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
void split(string str) {
stringstream ss(str);
string word;
while (ss >> word) {
cout << word << endl;
}
}
int main() {
string st = "Blood from heaven is mortal";
cout << "Blood from heaven is mortal" << endl;
split(st);
return 0;
}
আউটপুট
Blood from heaven is mortal Blood from heaven is mortal
উদাহরণ ২
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
void split(string str) {
stringstream ss(str);
string word;
while (ss >> word) {
cout << word << endl;
}
}
int main() {
string st = "type a text message";
cout << "type a text message" << endl;
split(st);
return 0;
}
আউটপুট
type a text message type a text message