#include<iostream>
#include<string>
#include<vector>
#include <cctype>
using namespace std;
int main()
{
vector<string>vs;
string temp,line,String;
int size,count,x=0;
bool f = false;
cout << "Enter elements: " << endl;
do
{
string str;
getline(cin, str);
vs.push_back(str);
cout << "Continue? (y/n)" << endl;
getline(cin, temp);
} while (temp.size() != 0 && temp == "y");
cout << endl;
cout << "Text:" << endl;
for (size_t i = 0; i < vs.size(); i++)
cout << vs[i] << endl;
cout << endl;
cout << "Enter size: ";
cin >> size;
cin.ignore();
cout << "Text:" << endl;
for (size_t j = 0; j < vs.size(); j++)
{
if (vs[j].size() >= size)
{
String = vs[j];
count = 0;
while (f == false)
if (!isalpha(String[size - 1]))
{
for (size_t k = 0; k < String.size(); k++)
{
line[x] = String[k];
count++;
if (x == size - 1)
{
cout << line << endl;
line.clear();
if (count == String.size()) f = true;
x = 0;
continue;
}
x++;
}
}
else
{
size_t y = String.size();
for (size_t k = String.size() - 1; k >= 0; k--)
{
if (isalpha(String[k])) y--;
else break;
}
for (size_t k = 0; k < y; k++)
{
line[x] = String[k];
count++;
if (x == size - 1)
{
cout << line << endl;
line.clear();
if (count == String.size()) f = true;
x = 0;
continue;
}
x++;
}
String.clear();
}
}
else cout << vs[j] << endl;
}
system("pause");
return 0;
}
Asked
Active
Viewed 1,541 times
1
Алексей
- 11
lineв выраженииline[x] = String[k];? Почему Выxсравниваете ниже сsize-1? Вы считаете, что размер не заданной строки будет равенsize? Или это я где-то пропустил ту часть, где Вы присваиваетеlineкакое-то значение и тем задаете размер строки? – Vladimir May 23 '18 at 18:59