Read string in and then output : string output « String « C++






Read string in and then output

   
#include <iostream>
#include <string>  

using namespace std;

int main()
{
   string string1; 
   string string2; 

   cout << "\nEnter a string: ";
   getline( cin, string1 );

   cout << "Enter a second string: ";
   getline( cin, string2 );

   cout << "\nFirst string: " << string1 << endl;
   cout << "Second string: " << string2 << endl;

   cout << endl;

   return 0;
}
  
    
    
  








Related examples in the same category

1.Output a string with copy function
2.Use of as istream_iterator iterator