New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

cin, cout recognized with <stdio.h>, not with <stdio>


Post Reply New Thread Subscribe

 
Thread Tools
MichiganDavid

 
MichiganDavid's Avatar
 
Member Since: Jan 21, 2009
Location: Midland, Michigan
Posts: 9
MichiganDavid is on a distinguished road
Mac Specs: MB Pro, 17", 2.5 GHz Intel

MichiganDavid is offline
I am working on a fairly simple C++ application as a "terminal utility" (i.e. no GUI). When I try to compile my application, I get the following error:

cin.getline(str,100); //this is the line of source

error: 'cin' was not declared in this scope

If I change the include statement from

#include <iostream>

to

#include <iostream.h>

then I get a warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h> etc.

However, the program compiles and runs. So, my question: why doesn't the recommended header (<iostream>) work in this context?

Thanks.
QUOTE Thanks
deer dance

 
deer dance's Avatar
 
Member Since: Jan 23, 2009
Location: Indiana
Posts: 162
deer dance has a little shameless behaviour in the past
Mac Specs: Soon to own

deer dance is offline
If you note my signature, I'm more familar with C, than with C++ .

However if I'm not mistaken, I believe that the proper header would be <iostream.h>.

Though I could be wrong, again I'm not the most familar with C++.


Proud Python Programmer/HTML Expert
Believer in Mac OS 7
QUOTE Thanks
mystic_fm

 
Member Since: Mar 15, 2007
Posts: 161
mystic_fm will become famous soon enough
Mac Specs: 17" MacBook Pro, 2.33GHz C2D, 2GB RAM

mystic_fm is offline
Actually, in C++, #include <iostream> is the recommended method.

To the original poster, I suspect your problem is that when you include <iostream>, cin is in the std namespace and you may not be using that namespace (whereas iostream.h does the latter for you). If you either use std::cin.getline(...) or add the line using std::cin or the line using namespace std, or in some other way use the namespace "std" to find "cin", the <iostream> version will probably compile and work for you.
QUOTE Thanks
MichiganDavid

 
MichiganDavid's Avatar
 
Member Since: Jan 21, 2009
Location: Midland, Michigan
Posts: 9
MichiganDavid is on a distinguished road
Mac Specs: MB Pro, 17", 2.5 GHz Intel

MichiganDavid is offline
Quote:
Originally Posted by mystic_fm View Post
Actually, in C++, #include <iostream> is the recommended method.

To the original poster, I suspect your problem is that when you include <iostream>, cin is in the std namespace and you may not be using that namespace (whereas iostream.h does the latter for you). If you either use std::cin.getline(...) or add the line using std::cin or the line using namespace std, or in some other way use the namespace "std" to find "cin", the <iostream> version will probably compile and work for you.
Aha, that makes sense. I'm a noob and was unaware of the namespace bit, though I've seen sample code with mention of it. Thanks very much.
QUOTE Thanks
MichiganDavid

 
MichiganDavid's Avatar
 
Member Since: Jan 21, 2009
Location: Midland, Michigan
Posts: 9
MichiganDavid is on a distinguished road
Mac Specs: MB Pro, 17", 2.5 GHz Intel

MichiganDavid is offline
mystic_fm,
Thanks. Adding the line
using namespace std;
at the beginning worked fine.
David
QUOTE Thanks
njdevilfan26

 
Member Since: Jan 27, 2009
Posts: 8
njdevilfan26 is on a distinguished road

njdevilfan26 is offline
in objective c which is similar to c++ it would be #include<iostream.h>
QUOTE Thanks

Post Reply New Thread Subscribe


« Applescript guru? help debug my script? | Open GL ES »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

All times are GMT -4. The time now is 11:45 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?