Дана строка, содержащая текст, заканчивающийся точкой. вывести на экран слова, содержащие три буквы. c++ // 9rab.cpp: определяет точку входа для консольного приложения. // #include "stdafx.h" #include #include using namespace std; int main() { setlocale(lc_all, "russian"); string s; cout < < "введите фразу" < < endl; cin > > s; cout < < endl; for (int i = 0; i < s.length(); i++) { if (s.length() == 3) { cout < < s < < endl; } } return 0; } не работает,почему? может по другому как-то?
//Вот как сделал я:
#include <iostream>
using namespace std;
int main()
{
string str;
int Size;
int ArrIndex = 0;
cout « "Enter string: ";
getline (cin, str);
string Element[str.length()];
for (int i = 0; i < str.length(); i++)
{
if (str[i] != ' ' && str[i] != '.')
Element[ArrIndex] += str[i];
else
ArrIndex++;
}
cout « endl;
for (int j = 0; j < str.length(); j++)
{
Size = 0;
for (int k = 0; k < Element[j].length(); k++)
Size++;
if (Size == 3)
cout « Element[j] « endl;
}
return 0;
}