Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

g++ UNIX:  cin.get()   and  accessint day info

Posted on 1997-06-03
1
332 Views
Last Modified: 2006-11-17
> Could anyone email me help on using cin.get() on a unix system w/ g++?

> cin.get() seems to still wait for a return character.  I would like to
> just grab one char (similar to how PINE needs only one control char to
> proceed).

> Our current project also requires the day-of-the-week.
> For example, If the user inputs "02/14/99" I need to know that that day
> is a Sunday.  I have thought of computing the information, but was
> wondering if I can access the system (UNIX) within a c++ program to tell
> me the day-of-week.

> Help is greatly appreciated.
> Please reply via email.                             -Brett
0
Comment
Question by:flood
1 Comment
 
LVL 4

Accepted Solution

by:
jos010697 earned 100 total points
ID: 1163803
The way stdin is buffered is beyond the scope of control
of a C++ program, all you can do is set the terminal
driver to the appropriate mode. If you do something
like:

   system("stty raw");

begore calling cin.get(), your terminal will be set to a
non-canonical mode, i.e. no buffering is performed whatsoever.
After all reading is done, reset your terminal to cooked mode
again by calling:

   system("stty sane");

Note that this is a quick hack, there are faster (and better)
ways of doing this. Check your man pages for ioctl(),
termio() etc.

About the date stuff, check your man pages for mktime(),
gmtime() etc. They'll help you out ...

kind regards,

Jos aka jos@and.nl

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question