C++/Console/cin getline


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++ эксперт
Перейти к: навигация, поиск

Using getline() to read char array

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


Using getline() to read string in

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