C++/Console/cin get

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Concatenate get() with Parameters

<source lang="cpp">

  1. 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;

}


 </source>


Using get() with a Character Array

<source lang="cpp">

  1. 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;

}


 </source>


Using get() with no parameters.

<source lang="cpp">

  1. include <iostream>

using namespace std; int main() {

  char ch;
  while ( (ch = cin.get()) != EOF)
  {
     cout << "ch: " << ch << endl;
  }
  cout << "\nDone!\n";
  return 0;

}


 </source>


Using get() with No Parameters to read single char

<source lang="cpp">

  1. include <iostream>

using namespace std; int main() {

  char ch;
  while ( (ch = cin.get()) != EOF)
  {
     cout << "ch: " << ch << endl;
  }
  cout << "\nDone!\n";
return 0;

}


 </source>


Using get() with parameters.

<source lang="cpp">

  1. 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;

}


 </source>


Using get() with Parameters to read single char in

<source lang="cpp">

  1. 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;

}


 </source>