CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2011
    Posts
    8

    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
    Posts
    598

    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
    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main () {
    
      char ch;
      ofstream outfile ("test.txt");
    
      do {
        ch=cin.get();
        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
  •  





Click Here to Expand Forum to Full Width

Featured