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

Joined
Jan 21, 2009
Messages
9
Reaction score
0
Points
1
Location
Midland, Michigan
Your Mac's Specs
MB Pro, 17", 2.5 GHz Intel
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.
 
Joined
Jan 23, 2009
Messages
162
Reaction score
1
Points
18
Location
Indiana
Your Mac's Specs
Soon to own
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++.
 
Joined
Mar 15, 2007
Messages
161
Reaction score
4
Points
18
Your Mac's Specs
17" MacBook Pro, 2.33GHz C2D, 2GB RAM
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.
 
OP
MichiganDavid
Joined
Jan 21, 2009
Messages
9
Reaction score
0
Points
1
Location
Midland, Michigan
Your Mac's Specs
MB Pro, 17", 2.5 GHz Intel
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.
 
OP
MichiganDavid
Joined
Jan 21, 2009
Messages
9
Reaction score
0
Points
1
Location
Midland, Michigan
Your Mac's Specs
MB Pro, 17", 2.5 GHz Intel
mystic_fm,
Thanks. Adding the line
using namespace std;
at the beginning worked fine.
David
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top