vector
of the string
takes input from a given string
.
Input: Hello World
Expected Output: Hello World
Actual Output: Hello
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s1;
getline(cin, s1);
vector<string> vs1;
string s2;
for (int i = 0; i < s1.size(); i++) {
if (s1[i] != ' ') {
s2.push_back(s1[i]);
continue;
}
if (s1[i] == ' ' || i == s1.size() - 1) {
vs1.push_back(s2);
s2.clear();
}
}
for (string t : vs1) {
cout << t << " ";
}
return 0;
}