35657

Untitled

Jan 20th, 2024
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <Windows.h> // нужна для работы SetConsole
  5.  
  6. using namespace std;
  7.  
  8. void DelChar(char* str, char ch) {
  9.     char* temp = new char[strlen(str) + 1];
  10.     int count = 0;
  11.     for (int i = 0; i <= strlen(str); i++) {
  12.         if (str[i] != ch) {
  13.             temp[count++] = str[i];
  14.         }
  15.     }
  16.     strcpy(str, temp);
  17. }
  18.  
  19. int main() {
  20.  
  21.     SetConsoleCP(1251); // установка кодировки 1251 в поток ввода
  22.     SetConsoleOutputCP(1251); // установка кодировки 1251 в поток вывода (то же, что setlocale)
  23.  
  24.     char line[40];
  25.     char ch;
  26.  
  27.     cout << "Введите строку: ";
  28.     gets_s(line);
  29.     cout << "Введите символ: ";
  30.     cin >> ch;
  31.     DelChar(line, ch);
  32.     cout << line << endl;
  33.    
  34. }
Advertisement
Add Comment
Please, Sign In to add comment