Thread: getchar() from c to c++ ?

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    27

    getchar() from c to c++ ?

    well is there a similar function in c++ ?

    instead of getchar() in C i wanna use a similar function for c++ .

    and how can i read the buffer from cin .. ?

    (i know i can clear it with cin.clear() but i want to read it)

    e.g with cin >> number if the user writes more characters after the number.

    thanks in advance

  2. #2
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    You could try cin.get() ;

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    27
    a friend told me that cin.get() had a pointer as parameter...

    but i tested it now and you are right .. next time i'll check before asking..

  4. #4
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by neoragexxx
    a friend told me that cin.get() had a pointer as parameter...
    your friend was right. there are lots of overloaded versions
    Code:
      int get();
      istream& get( char& ch );
      istream& get( char* buffer, streamsize num );
      istream& get( char* buffer, streamsize num, char delim );
      istream& get( streambuf& buffer );
      istream& get( streambuf& buffer, char delim );
    Kurt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getchar() problem
    By jlharrison in forum C Programming
    Replies: 6
    Last Post: 01-25-2006, 02:49 PM
  2. getchar buffer size
    By oncemyway in forum C Programming
    Replies: 3
    Last Post: 08-02-2005, 12:49 AM
  3. getchar() problem from K&R book
    By anemicrose in forum C Programming
    Replies: 13
    Last Post: 04-04-2004, 11:06 PM
  4. help with getchar lol
    By Taco Grande in forum C Programming
    Replies: 5
    Last Post: 03-18-2003, 09:25 PM
  5. Can anybody take a look at this?
    By TerryBogard in forum C Programming
    Replies: 10
    Last Post: 11-21-2002, 01:11 PM