Здравствуйте, как получить все строки, пока не найдете пробел, и push_back слова до пробела во втором повороте Для l oop, чтобы начать получать все строки после пробела и снова, пока не найти пробел, это мой код
для Например, это предложение . [0] == 'bbbb' ve c. [1] == 'aaaa' ve c. [2] == 'f' ve c. [3] == 'ffg'
Спасибо за продвинутый
это мои 2 кода, оба не работают
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
string sentece;
getline(cin, sentece);
vector<char> words;
for (int i = 0; i < sentece.size(); ++i)
{
while (sentece.substr(i, ' '))
{
if(isalpha(sentece.at(i)))
{
words.push_back(sentece.at(i));
}
}
}
cout << words[0] << '\n';
cout << words[1] << '\n';
cout << words[2] << '\n';
for(const auto& a : words)
{
cout << a;
}
return 0;
}
//==================================================================
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
string sentece;
getline(cin, sentece);
vector<char> words;
for (int i = 0; i < sentece.size(); ++i)
{
while (sentece.at(i) != ' ')
{
if(isalpha(sentece.at(i)))
{
words.push_back(sentece.at(i));
}
if(sentece.at(i) == ' ')
{
break;
}
}
}
cout << words[0] << '\n';
cout << words[1] << '\n';
cout << words[2] << '\n';
for(const auto& a : words)
{
cout << a;
}
return 0;
}