Solved

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

Posted on 1997-06-03
1
320 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

929 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now