Results 1 to 6 of 6
  1. #1
    cin, cout recognized with <stdio.h>, not with <stdio>
    MichiganDavid's Avatar
    Member Since
    Jan 21, 2009
    Location
    Midland, Michigan
    Posts
    9
    Specs:
    MB Pro, 17", 2.5 GHz Intel
    Question cin, cout recognized with <stdio.h>, not with <stdio>
    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.

  2. #2
    cin, cout recognized with &lt;stdio.h&gt;, not with &lt;stdio&gt;
    deer dance's Avatar
    Member Since
    Jan 23, 2009
    Location
    Indiana
    Posts
    162
    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++.

    Proud Python Programmer/HTML Expert
    Believer in Mac OS 7

  3. #3
    cin, cout recognized with &lt;stdio.h&gt;, not with &lt;stdio&gt;

    Member Since
    Mar 15, 2007
    Posts
    161
    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.

  4. #4
    cin, cout recognized with &lt;stdio.h&gt;, not with &lt;stdio&gt;
    MichiganDavid's Avatar
    Member Since
    Jan 21, 2009
    Location
    Midland, Michigan
    Posts
    9
    Specs:
    MB Pro, 17", 2.5 GHz Intel
    Smile
    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.

  5. #5
    cin, cout recognized with &lt;stdio.h&gt;, not with &lt;stdio&gt;
    MichiganDavid's Avatar
    Member Since
    Jan 21, 2009
    Location
    Midland, Michigan
    Posts
    9
    Specs:
    MB Pro, 17", 2.5 GHz Intel
    mystic_fm,
    Thanks. Adding the line
    using namespace std;
    at the beginning worked fine.
    David

  6. #6
    cin, cout recognized with &lt;stdio.h&gt;, not with &lt;stdio&gt;

    Member Since
    Jan 27, 2009
    Posts
    8
    in objective c which is similar to c++ it would be #include<iostream.h>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem with cout, complex type on Xcode
    By mk ii in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 01-24-2013, 05:40 PM
  2. Airport Not Recognized
    By kevinwwfg in forum Internet, Networking, and Wireless
    Replies: 4
    Last Post: 12-06-2010, 04:56 PM
  3. OS 10.4.xx not recognized??
    By coreymc in forum OS X - Operating System
    Replies: 11
    Last Post: 10-03-2007, 10:54 PM
  4. Keyboard not recognized??
    By Marie_A in forum OS X - Operating System
    Replies: 1
    Last Post: 09-15-2006, 07:15 AM
  5. gcc compiler, no stdio.h found
    By lzco in forum OS X - Development and Darwin
    Replies: 6
    Last Post: 10-21-2005, 04:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •