#include
#include
#include
#include
using namespace std;
int main() {
string s, w;
cout << "string? ";
getline(cin, s);
istringstream iss(s);
vector
while (iss >> w) v.push_back(w);
cout << "array:\n";
for (int c = 0; c < v.size(); ++c) cout << v[c] << endl;
}
Или:
#include
#include
#include
using namespace std;
int main() {
string s, d = " ,.;!" /* добавить разделителей по вкусу */ ;
cout << "string? ";
getline(cin, s);
vector
int b, e = 0;
while ((b = s.find_first_not_of(d, e)) != s.npos) {
e = s.find_first_of(d, b);
v.push_back(s.substr(b, e - b));
b = e;
}
cout << "array:\n";
for (int c = 0; c < v.size(); ++c) cout << v[c] << endl;
}
функция сплит
пройтись по строке копируя символы, при встрече пробела начинать копировать символы в следующую строку-элемент массива строк