C++/Console/cin get


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
Перейти к: навигация, поиск

Concatenate get() with Parameters

  
#include <iostream>
int main()
{
   char a, b, c;
   std::cout << "Enter three letters: ";
   std::cin.get(a).get(b).get(c);
   std::cout << "a: " << a << "\nb: ";
   std::cout << b << "\nc: " << c << std::endl;
   return 0;
}


Using get() with a Character Array

  
#include <iostream>
using namespace std;
int main()
{
   char stringOne[256];
   char stringTwo[256];
   cout << "Enter string one: ";
   cin.get(stringOne,256);
   cout << "stringOne: " << stringOne << endl;
   cout << "Enter string two: ";
   cin >> stringTwo;
   cout << "StringTwo: " << stringTwo << endl;
   return 0;
}


Using get() with no parameters.

  
#include <iostream>
using namespace std;
int main()
{
   char ch;
   while ( (ch = cin.get()) != EOF)
   {
      cout << "ch: " << ch << endl;
   }
   cout << "\nDone!\n";
   return 0;
}


Using get() with No Parameters to read single char

  
#include <iostream>
using namespace std;
int main()
{
   char ch;
   while ( (ch = cin.get()) != EOF)
   {
      cout << "ch: " << ch << endl;
   }
   cout << "\nDone!\n";
 return 0;
}


Using get() with parameters.

  
#include <iostream>
using namespace std;
int main()
{
   char a, b, c;
   cout << "Enter three letters: ";
   cin.get(a).get(b).get(c);
   cout << "a: " << a << "\nb: " << b << "\nc: " << c << endl;
 return 0;
}


Using get() with Parameters to read single char in

  
#include <iostream>
using namespace std;
int main()
{
   char a, b, c;
   cout << "Enter three letters: ";
   cin.get(a).get(b).get(c);
   cout << "a: " << a << "\nb: " << b << "\nc: " << c << endl;
   return 0;
}