I assume that it’s a matter of the line, but that’s what I need to write down. With the line I'm on "you", so .. it turns out. If the code looks incorrectly formed, then excuse me: in Stack Overflow, it is a little difficult for me to write code so that everything correctly renders.

#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <iomanip> #include <Windows.h> using namespace std; enum Mask { UPPER = 128, SPACE_BETWEEN_LETTERS = 64, NEWLINE = 32, NOTHING = 16, COLOR_AQUA = 8, COLOR_GREEN = 4, COLOR_BLUE = 2, COLOR_BLACK = 1 }; void uppercase(char str[]) { char* step = str; while (*step != '\0') { *step = toupper(*step); ++step; } } void lowercase(char str[]) { char* step = str; while (*step != '\0') { *step = tolower(*step); ++step; } } void space_between_letters(char *&str) { size_t tmp_size = strlen(str) * 2; char *tmp = new char[tmp_size]; for (size_t i = 0, j = 0; j < tmp_size;) { if (j % 2 == 0 && str[i] != ' ') { tmp[j] = ' '; } else { tmp[j] = str[i]; ++i; } ++j; } tmp[tmp_size - 1] = '\0'; delete[] str; str = tmp; } void new_line(char *&str) { str[strlen(str)] = '\n'; } void nothing() { cout << "\n OMG, nothing happened! (kidding: this cout was activated) \n"; } void main() { setlocale(LC_ALL, "Russian"); HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); unsigned char settings = 0; int size; cout << "Введите размер строки: "; cin >> size; char *str = new char[size] {'\0'}; strcpy(str, "Some text for test"); char user_choise; cout << "Введите саму строку (обязательно поставьте точку, когда строка будет завершена): "; cin.getline(str, size, '.'); system("cls"); cout << "Большие (U) или маленькие (L) буквы? (U/L) \n Ваш выбор: "; cin >> user_choise; if (user_choise == 'U') settings = Mask::UPPER; else lowercase(str); system("cls"); cout << "Ставить ли пробелы между буквами? (Y/N) \n Ваш выбор: "; cin >> user_choise; if (user_choise == 'Y') settings = Mask::SPACE_BETWEEN_LETTERS; system("cls"); cout << "Ставить ли Enter (\\n) после текста? (Y/N) \n Ваш выбор: "; cin >> user_choise; if (user_choise == 'Y') settings = Mask::NEWLINE; system("cls"); cout << "Вызвать ли nothing? (Y/N) \n Ваш выбор: "; cin >> user_choise; if (user_choise == 'Y') settings = Mask::NOTHING; system("pause"); system("cls"); cout << "Выберите цвет Вашей строки: \n"; cout << "\t 3) Aqua \n"; cout << "\t 2) Green \n"; cout << "\t 1) Blue \n"; cout << "\t 0) Black \n"; cout << " \n Ваш выбор: "; cin >> user_choise; if (user_choise == '3') { settings = Mask::COLOR_AQUA; } if (user_choise == '2') { settings = Mask::COLOR_GREEN; } if (user_choise == '1') { settings = Mask::COLOR_BLUE; } if (user_choise == '0') { settings = Mask::COLOR_BLACK; } if ((settings & Mask::UPPER) == Mask::UPPER) { uppercase(str); } if ((settings & Mask::SPACE_BETWEEN_LETTERS) == Mask::SPACE_BETWEEN_LETTERS) { space_between_letters(str); } if ((settings & Mask::NEWLINE) == Mask::NEWLINE) { new_line(str); } if ((settings & Mask::NOTHING) == Mask::NOTHING) { nothing(); } if ((settings & Mask::COLOR_AQUA) == Mask::COLOR_AQUA) { SetConsoleTextAttribute(h, 3); } if ((settings & Mask::COLOR_GREEN) == Mask::COLOR_GREEN) { SetConsoleTextAttribute(h, 2); } if ((settings & Mask::COLOR_BLUE) == Mask::COLOR_BLUE) { SetConsoleTextAttribute(h, 1); } if ((settings & Mask::COLOR_BLACK) == Mask::COLOR_BLACK) { SetConsoleTextAttribute(h, 0); } cout << "Строка, которая вышла: " << str << endl; delete[] str; system("pause"); exit(1); } 
  • Can you compile this code at all? - Andrej Levkovitch
  • Well, I think you have some problems with getline - Andrej Levkovitch
  • Please explain more precisely what the problem is. - Cerbo
  • Such a thing: cin.getline somehow incorrectly works, for example, by entering text and pressing Enter, the input continues until the text size crosses the specified limit (size). I know that it's a null terminator, I tried to put the \ n function instead of \ 0, but when writing the size of the array and pressing Enter, text input is skipped. What to do with it - I do not know. - pragma

1 answer 1

Well, string is not a char[] ! Choose one, something like

 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <iomanip> #include <conio.h> #include <string> using namespace std; enum Mask { UPPER = 128, LOWER = 64, SPACE_BETWEEN_LETTERS = 32, NEWLINE = 16, }; void uppercase(string&str) { for(int i = 0; i < str.length(); ++i) str[i] = toupper(str[i]); // позволяет сделать буквы заглавными cout << "Upper: " << str << endl; } void lowercase(string&str) { for(int i = 0; i < str.length(); ++i) str[i] = tolower(str[i]); } void space_between_letters(string&str) { // пробелы между буквами string res; for(int i = 0; i < str.length(); ++i) res = res + str[i] + " "; str = res; } void newline(string&str) { // \n после текста str += '\n'; } int main() { setlocale(0, "rus"); unsigned char settings = 0; unsigned char user_choise = 0; string str; system("cls"); cout << "Введите строку: "; getline(cin, str); system("cls"); cout << "Большие (U) или маленькие (L) буквы? \n Ваш выбор: "; cin >> user_choise; if (user_choise == 'U') settings |= Mask::UPPER; else if (user_choise == 'L') settings |= Mask::LOWER; system("cls"); cout << "Ставить ли пробелы между буквами? \n Ваш выбор (Y/n): "; cin >> user_choise; if (user_choise == 'Y') settings |= Mask::SPACE_BETWEEN_LETTERS; system("cls"); cout << "Ставить ли Enter (\\n) после текста? \n Ваш выбор: "; cin >> user_choise; if (user_choise == 'Y') settings |= Mask::NEWLINE; system("cls"); if ((settings & Mask::UPPER) == Mask::UPPER) { uppercase(str); } if ((settings & Mask::LOWER) == Mask::LOWER) { lowercase(str); } if ((settings & Mask::SPACE_BETWEEN_LETTERS) == Mask::SPACE_BETWEEN_LETTERS) { space_between_letters(str); } if ((settings & Mask::NEWLINE) == Mask::NEWLINE) { newline(str); } cout << hex << settings << endl; cout << str << endl; system("pause"); } 

Just keep in mind that there will still be problems with the Russian letters entered ...

  • And if you put setlocale (LC_ALL, "Russian"), then the problem will still be? - pragma