What is the function of cin.get(c)?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: What is the function of cin.get(c)?

  1. #1
    Join Date
    Jun 2011

    What is the function of cin.get(c)?

    i know it takes one character at a time but if i give input HELLO WORLD what it will take then just H. And what will cout.put(c) print then?

  2. #2
    Join Date
    Apr 2009

    Re: What is the function of cin.get(c)?

    Write a little program and test by yourself.
    See the documentation:
    - http://www.cplusplus.com/reference/i...m/istream/get/ ,
    - http://www.cplusplus.com/reference/i...m/ostream/put/ ,
    - http://www.cplusplus.com/reference/iostream/cin/ ,
    - http://www.cplusplus.com/reference/iostream/cout/ .

    Edit: Sorry, I forgot to answer your questions.

    Q: What is the function of cin.get(c)?
    A: The function is to get one character.

    Q: What will cout.put(c) print?
    A: It will print the c character.

    The following example will help you understand these functions
    #include <iostream>
    #include <fstream>
    using namespace std;
    int main () {
      char ch;
      ofstream outfile ("test.txt");
      do {
        outfile.put (ch);
      } while (ch!='.');
      return 0;
    This example writes to a file everything the user types until a dot (.) is typed.
    Last edited by olivthill2; June 29th, 2011 at 04:57 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)