The C++ standard libraries furnish a substantial wind up of input/output.
C++ I/O occurs in streams, which are lineups of data. If data flow from a device like a keyboard to main memory is called input operation and if data flow back from main memory to a device like a display screen is called output operation.
However, in cin extraction always considers spaces like (tabs, new-line...),it only outputs the single word not the whole content .
To output an entire content there exists a predefined function in C++ library, called getline. For example:
// cin with strings
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string info;
cout << "What is your name? ";
getline (cin, info);
cout << "Hello " << info << ".\n";
cout << "What is your favorite book? ";
getline (cin, info);
cout << "I like " << info << " too!\n";
cout << "Who is your favorite author? ";
getline (cin, info);
cout << "Oh!! GREAT " << info << " Cool\n";
return 0;
}
OUTPUT:-
What is your name? Steve Marks
Hello Steve Marks.
What is your favorite book? The Terminator.
I like The Terminator too!
Who is your favorite author? Sherlock Homes
Oh!! GREAT Sherlock Homes Cool.
0 Comment(s)