C++/Console/cin get
Содержание
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;
}