473,473 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How can cin.get() != EOF work on Mac OS X (like on SunOS) ?

1 New Member
The following code works on SunOS but not on MacOS X. On the Mac, the second "cout <<" prints to the screen but the program quits without getting any input. Can anyone explain this? Thanks. (I've read through all the threads I could find to solve this.)

Expand|Select|Wrap|Line Numbers
  1. // iotest.cc
  2. //
  3. #include <iostream>
  4. using std::cin;
  5. using std::cout;
  6. using std::endl;
  7.  
  8. int main()
  9. {
  10.     int iChar;
  11.  
  12.     //-------------------------------
  13.     // This works on SunOS and MacOSX
  14.     //-------------------------------
  15.     cout << "\nEnter a sentence followed by <cr><ctrl-d>:" << endl;
  16.  
  17.     while ( ( iChar = cin.get() ) != EOF )
  18.     {
  19.         cout.put( iChar );
  20.     }
  21.     cout.put('\n');
  22.  
  23.     cin.clear( );
  24.  
  25.  
  26.     //-------------------------------
  27.     // This works on SunOS but not on MacOSX
  28.     //-------------------------------
  29.     cout << "\nEnter a sentence followed by <cr><ctrl-d>:" << endl;
  30.  
  31.     while ( ( iChar = cin.get() ) != EOF )
  32.     {
  33.         cout.put( iChar );
  34.     }
  35.  
  36.     cout.put('\n');
  37.  
  38.     cin.clear( );
  39.  
  40.     return 0;
  41. }
  42.  
Jan 23 '07 #1
1 4218
horace1
1,510 Recognized Expert Top Contributor
have a look at
http://forums.macosxhints.com/archive/index.php/t-55717.html

which discusses this problem
it appears that when CTRL/D is entered some systems "just" return EOF but OSX also closes the stdin stream (hence killing the program).
Jan 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: gaool | last post by:
Hello, I try to launch a Python script on SunOS system but I have this error: """Traceback (most recent call last): File "ihm1_1.py", line 3, in ? from Tkinter import * File...
1
by: gaool | last post by:
Hello, I wrote a python script (python 2.3.3) to send some commands to a programm and to show on the screen the responses of this programm. I use "Pipedream.py" module in my script to speak with...
2
by: Yeounkun, Oh | last post by:
Hello, I want to know the name of function() in program. In "gcc", I know that __FUNCTION__ macro is used for getting that. but in "cc", __FUNCTION__ macro does not exist. I can't find function...
19
by: LP | last post by:
I am using (trying to) CR version XI, cascading parameters feature works it asks user to enter params. But if page is resubmitted. It prompts for params again. I did set...
2
by: cmk128 | last post by:
Hi How can we force all the class A's subclass inherit all its functions? Or how can we force class B to inherit function abc()? thanks from Peter (cmk128@hotmail.com) class A{ public:...
17
by: arne.muller | last post by:
Hello, I just had to find out that a program that runs fine under linux and True64 alpha crashed with a segmentation fault under SunOS 5.8. I drilled down and it appears that if the ...
2
by: semut | last post by:
Any IDE for SunOS 5.8 C++ programming? open source or non open source. thanks
0
by: mathieu | last post by:
Hello, I am struggling with the following error on a SunOS C++ compiler: "/opt/SUNWspro/prod/include/CC/Cstd/./map", line 251: Error: Multiple declaration for std::map<const unsigned...
1
by: partofthething | last post by:
I've been struggling with this all day. I am trying to get Python 2.5 running with the BerkeleyDB bindings provided by bsddb. First, I downloaded the BerkeleyDB system (version 4.5) from...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.