Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

c++ coding question cin.get()?

i was wondering if i could put like cin.get(y) so it waits for y to be entered. is this possible.

3 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    If y is a char, it will only get one char.

    If y is a char array, you would need to pass in the number of characters + 1 that you want to get.

    If y is a char array, you could also pass in the character that acts as the end of line character.

    Here are some web pages that describe how to use cin.get

    http://www.cplusplus.com/reference/iostream/istrea...

    http://www.minich.com/education/wyo/cplusplus/cplu...

    http://www.cplusplus.com/forum/general/465/

    Hope that helps.

  • cin object

    Standard input stream

    cin is an object of class istream that represents the standard input stream. It corresponds to the cstdio stream stdin.

    By default, most systems get their standard input from the keyboard, therefore cin is generally expected to get information from the user, although there are many cases where this can be redirected to some other source.

    Because cin is an object of class istream, we can retrieve characters from cin either as formatted data using the extraction operator (>>) or as unformatted data using the read member function, among others (see istream).

    cin is tied (see ios::tie) to the standard output stream cout, which means that cout's buffer is flushed (see ostream::flush) before each i/o operation performed on cin.

  • 1 decade ago

    No, that wouldn't be correct syntax.

    A normal

    cin >> y;

    will wait for an input before the program continues.

    cin.get(y) would mean that "cin" is an object of a class, and get() was a function of that class. I mean you could write up a class to do that but it would be rather pointless.

Still have questions? Get your answers by asking now.