Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Input Output

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 468
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: