getchar() from c to c++ ?

This is a discussion on getchar() from c to c++ ? within the C++ Programming forums, part of the General Programming Boards category; well is there a similar function in c++ ? instead of getchar() in C i wanna use a similar function ...

  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
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    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
    ZuK
    ZuK is offline
    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, 01:49 AM
  3. getchar() problem from K&R book
    By anemicrose in forum C Programming
    Replies: 13
    Last Post: 04-05-2004, 12:06 AM
  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21