Advertisement
niks32

166

Apr 9th, 2020
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. // nikita166.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "iostream"
  6. #include <conio.h>
  7. #include <Windows.h>
  8.  
  9.  
  10. void getCharMass(char *name, int size) {
  11.     int counter = 0;
  12.     int tempCharCode;
  13.  
  14.     while (counter < size)
  15.     {
  16.         tempCharCode = _getch();
  17.  
  18.         if (tempCharCode == 13) {
  19.             std::cout << std::endl;
  20.             name[counter] = '\0'; //Знак окончания строки
  21.             break;
  22.         }
  23.  
  24.         name[counter] = (char)tempCharCode;
  25.         std::cout << name[counter];
  26.         counter++; 
  27.     }
  28. }
  29.  
  30.  
  31. int _tmain(int argc, _TCHAR* argv[])
  32. {
  33.     SetConsoleCP(1251);// установка кодовой страницы win-cp 1251 в поток ввода
  34.     SetConsoleOutputCP(1251); // установка кодовой страницы win-cp 1251 в поток вывода
  35.  
  36.     char name[30];
  37.     char otchestvo[30];
  38.     char *initialText[] = { "Как Вас зовут?", "Введите свое имя, затем нажмите <Enter>",
  39.         "Введите свое отчество, затем нажмите <Enter>", " -> " };
  40.    
  41.     std::cout << initialText[0] << std::endl
  42.         << initialText[1] << std::endl << initialText[3];
  43.     getCharMass(name, 30);
  44.    
  45.     std::cout << std::endl << initialText[2] << std::endl << initialText[3];
  46.     getCharMass(otchestvo, 30);
  47.  
  48.     std::cout << "Здравствуйте, " << name << " " << otchestvo << std::endl;
  49.  
  50.     system("pause");
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement