The program transfers part of the text to a new line if the number of characters exceeds the allowed value in the line.
Algorithm of the program: 1. There is a text. How It Works
Enter the number of valid characters per line, I enter n = 4.
Using the for loop, the program selects the first n characters and places them in a new type of string and searches among them for the possibility of fulfilling the division condition: two consecutive vowels can be divided if there is a consonant in front of the first, and at least one letter follows the second this is considered together with the preceding vowel as a whole). If there is no such possibility, the program stops the robot.
I had a problem after the for loop where I want to put the first n characters in the new type string, the compiler compiles the program, but when it comes to the code section, the program crashes:
cout << clone.insert(str.find(str[nom]), str);
The code itself:
#include <iostream> #include <vector> #include <string> #include <windows.h> #include <sstream> #include <iterator> using namespace std; void delitel(string str, int i, int n); int main() { setlocale(LC_ALL, "Russian"); SetConsoleCP(1251); SetConsoleOutputCP(1251); vector<string> arr; string str("Привеет Как Дела"); string delim(" "); size_t prev = 0; size_t next; size_t delta = delim.length(); int i; cout << "Введи количество символов в строке: "; cin >> i; while ((next = str.find(delim, prev)) != string::npos) { //Отладка-start string tmp = str.substr(prev, next - prev); cout << tmp << " "; //Отладка-end arr.push_back(str.substr(prev, next - prev)); prev = next + delta; } //Отладка-start string tmp = str.substr(prev); cout << tmp << endl; //Отладка-end arr.push_back(str.substr(prev)); cout << endl; int n; n = str.size(); if (n > i) delitel(str, i, n); system("pause"); } void delitel(string str, int i, int n) { int nom; string clone; for (nom = 0; nom <= i; nom++) { cout << str[nom]; } cout << clone.insert(str.find(str[nom]), str); }