locked
1st timer problems with => #include <iostream.h> Vs. #include <iostream>

    Question

  • Hi,

    I just started with C++ and they say starting is the difficult part, well after what happened to me I'd agree.

    I have this problem with #include <iostream.h>

    Code:

    #include <iostream.h>

    int main()
    {
       cout << "Hello World!\n";
           return 0;
    }

    Error: PS: I used %dir% instead of the long boring dir. Stick out tongue

    ------ Build started: Project: day 1, Configuration: Debug Win32 ------
    Compiling...
    yo.cpp
    %dir%\yo.cpp(1) : fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory
    Build log was saved at "file://%dir%\Debug\BuildLog.htm"
    day 1 - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    I've been looking around on the Forums and I found this:
    (1)-http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=462900&SiteID=1
    (2)-http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3229126&SiteID=1

    Working from (2):
    Quote:
    "<iostream> is normally stored in the C:\Program Files\Microsoft Visual Studio 8\VC\include folder.  First check if it is still there.  Then choose Tools + Options, Projects and Solutions, VC++ Directories, choose "Include files" in the "Show Directories for"  combobox and double-check that $(VCInstallDir)include is on top of the list." - nobugz

    I went to my folder "C:\Program Files\Microsoft Visual Studio 9.0\VC\include"
    and no file "iostream.h" were found, but the file "iostream" were there.
    So I went to Google and I cannot find the file to download.
     
    So lets work with iostream, because iostream.h is not there.
    Code:

    #include <iostream>

    int main()
    {
       cout << "Hello World!\n";
           return 0;
    }

    Error:

    ------ Build started: Project: day 1, Configuration: Debug Win32 ------
    Compiling...
    yo.cpp
    %dir%\yo.cpp(5) : error C2065: 'cout' : undeclared identifier
    Build log was saved at "file://%dir%\day 1\Debug\BuildLog.htm"
    day 1 - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Working from (1):

    IF I say <iostream> and not <iostream.h> then it gives me this:
    error C2065: 'cout' : undeclared identifier

    Quote part:
    "

    (1) Put this statement immediately after the #include:

     

    Code Snippet

     

     

    using namepace std;

     

     

    (2) Put these statements immediately after the #include:

     

    Code Snippet

     

     

    using std::cout;
    using std::cin;
    using std:endl;

     

     

    (3) Change your code to this:

     

    std::cout << "\nEnter radius: " ;
    std::cin >> radius ;
    area = 3.14159 * radius * radius ;
    std::cout << "Area = "<< area ;

    " - WayneAKing

    Quote try (1)
    "using namepace std;"
    Code:

    #include <iostream>
    using namepace std;

    int main()
    {
       cout << "Hello World!\n";
           return 0;
    }

    Error:

    ------ Build started: Project: day 1, Configuration: Debug Win32 ------
    Compiling...
    yo.cpp
    %dir%\yo.cpp(2) : error C2146: syntax error : missing ';' before identifier 'std'
    %dir%\yo.cpp(2) : error C2873: 'namepace' : symbol cannot be used in a using-declaration
    %dir%\yo.cpp(2) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    %dir%\yo.cpp(2) : error C2365: 'std' : redefinition; previous definition was 'namespace'
    %dir%\yo.cpp(6) : error C2065: 'cout' : undeclared identifier
    Build log was saved at "file://%dir%\Debug\BuildLog.htm"
    day 1 - 5 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


    Quote try (2)
    "Put these statements immediately after the #include:"
    Code:

    #include <iostream>
    using std::cout;
    using std::cin;
    using std:endl;

    int main()
    {
       cout << "Hello World!\n";
           return 0;
    }

    Error:

    ------ Build started: Project: day 1, Configuration: Debug Win32 ------
    Compiling...
    yo.cpp
    %dir%\yo.cpp(4) : error C2143: syntax error : missing ';' before ':'
    %dir%\yo.cpp(4) : error C2873: 'std' : symbol cannot be used in a using-declaration
    %dir%\yo.cpp(4) : error C2059: syntax error : ':'
    %dir%\yo.cpp(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    Build log was saved at "file://%dir%\Debug\BuildLog.htm"
    day 1 - 4 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


    Quote try (3)
    "Change your code to this:"
    Code:

    #include <iostream>

    int main()
    {
       std::cout << "Hello World!\n";
           return 0;
    }

    Log:

    'day 1.exe': Loaded '%dir%\Release\day 1.exe', Symbols loaded.
    'day 1.exe': Loaded 'C:\Windows\System32\ntdll.dll'
    'day 1.exe': Loaded 'C:\Windows\System32\kernel32.dll'
    'day 1.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_e163563597edeada\msvcp90.dll'
    'day 1.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_e163563597edeada\msvcr90.dll'
    The program '[2840] day 1.exe: Native' has exited with code 0 (0x0).


    Only now the app works.
    How do I get my app to work like the Books say, thus I want my code to work if I type this:
    Code:

    #include <iostream.h>


    int main()

    {

    cout << "Hello World!\n";

    return 0;

    }


    Please notice: I use Visual C++ 2008 Express Edition V9.0


    I'd like if you can help me please.

    Monday, December 08, 2008 11:22 PM

Answers

  • Quote>no file "iostream.h" were found ...
    Quote>I went to Google and I cannot find the file to download.

     

    Don't do that. It would be a dumb move, and you were
    lucky you didn't find one. Using it would open a whole
    nest of problems, from which you probably would never
    recover. Never mix headers, lib files, etc. from different
    compilers or even different versions of the same compiler.

     

    Quote>#include <iostream>
    Quote>using namepace std;

    Quote>error C2873: 'namepace' : symbol cannot be used in a using-declaration

     

    Look at your spelling. Accuracy is important.
    It should be namespace.

     

    Quote>using std:endl;
    Quote>error C2873: 'std' : symbol cannot be used in a using-declaration
    Quote>error C2059: syntax error : ':'

     

    Check your punctuation and use of special characters.
    Accuracy is important.

     

    The scope resolution operator is :: not just : as you
    have.

     

    Quote>How do I get my app to work like the Books say

     

    To do that you would have to use a compiler which was
    created around the same time as the book was. The C++
    language has evolved over the past 20 or so years. Many
    changes have been made to it, and to the compilers which
    support it. You must always match code/books/compilers to
    the same era. Most books identify which compiler(s) the
    author used when writing the book and testing the code.

     

    - Wayne


     

    • Marked as answer by Spac3 Friday, December 12, 2008 1:57 PM
    Tuesday, December 09, 2008 8:07 PM

All replies

  • You'll need to get rid of the book, it is badly outdated.  Don't put double-quotes around the using statement.
    Tuesday, December 09, 2008 8:57 AM
    Moderator
  • Quote>no file "iostream.h" were found ...
    Quote>I went to Google and I cannot find the file to download.

     

    Don't do that. It would be a dumb move, and you were
    lucky you didn't find one. Using it would open a whole
    nest of problems, from which you probably would never
    recover. Never mix headers, lib files, etc. from different
    compilers or even different versions of the same compiler.

     

    Quote>#include <iostream>
    Quote>using namepace std;

    Quote>error C2873: 'namepace' : symbol cannot be used in a using-declaration

     

    Look at your spelling. Accuracy is important.
    It should be namespace.

     

    Quote>using std:endl;
    Quote>error C2873: 'std' : symbol cannot be used in a using-declaration
    Quote>error C2059: syntax error : ':'

     

    Check your punctuation and use of special characters.
    Accuracy is important.

     

    The scope resolution operator is :: not just : as you
    have.

     

    Quote>How do I get my app to work like the Books say

     

    To do that you would have to use a compiler which was
    created around the same time as the book was. The C++
    language has evolved over the past 20 or so years. Many
    changes have been made to it, and to the compilers which
    support it. You must always match code/books/compilers to
    the same era. Most books identify which compiler(s) the
    author used when writing the book and testing the code.

     

    - Wayne


     

    • Marked as answer by Spac3 Friday, December 12, 2008 1:57 PM
    Tuesday, December 09, 2008 8:07 PM
  • Thanks for the heads-up about the download.
    So tell me is <iostream> and <iostream.h> the same? <= Stupid question, but it needs to be answered.
    Because if I take the ".h" away then it works.

    Big thanks for the stupid mistake fix :P "
    It should be namespace."
    The app compiles with "
    using namespace std;" Thanks

        I need to show you something
    WayneAKing
        I'm new to c++ , and what do you do if your new? Copy Paste :D
        I found a post made by you.

        =>
    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3229126&SiteID=1
        Both the
    "using std::endl;" and the "using namespace std;" problems were typed by you :D
        Go have a look at the link or the quote (1st post)
       

    using std::cout;
    using std::cin;
    using std::endl;

     with this fixed now this works too. :D

    I'd like to know what is "using namespace std;" , what does it do?
    I read it - Use the following code with namespace std (standard?), what is namespace?


    So now that my app compiles, do you know of an free online book that I can work from to get my c++ going.
    I have a nice internet / network app to make,hope it works as nice as it does in my mind when i'm doen with it. :P

    Thanks for your time.

    Trust is a weakness.
    Friday, December 12, 2008 2:25 PM

  • Quote> Both the "using" problems were typed by you

    You see? I *told* you accuracy is important!

    My apologies. I've corrected the typos in that post.
    Hopefully not too many others were confused by it.

    Quote>what do you do if your new? Copy Paste

    Unfortunately, simply copying and pasting isn't always
    sufficient. I've seen numerous programming books with
    glaring errors in the included code (printed text.)
    This likely happens because the typesetters and even
    proof readers aren't knowledgeable in the topic, and
    may not realize that when it comes to programming code
    a paraphrase or approximation is not acceptable. You need
    to be flexible when adapting or using code written by
    others. Even compiler help examples may have errors - I
    can think of at least two glaring logic errors I've
    encountered in help file code.

    When it comes to vetting our own code, we often miss
    glaring mistakes completely. We tend to see what we
    expect to be there, not what is actually written. That's
    why having another programmer browse our code can be
    helpful, as they usually don't have the same preconceptions.
    Bear this case study in mind as you progress.

    Quote>is <iostream> and <iostream.h> the same?

    No. The .h extension was used in early C++ implementations,
    as that is what C uses for header files. But since the advent
    of ANSI/ISO standardization of C++ the .h must be omitted.
    Note that some early compilers accepted both, but even then
    there could be internal differences - such as iostreams being
    in the std namespace if the the .h was omitted and in the
    global namespace if it was used. Note that headers used
    with C have been renamed for use with C++ - such as stdio.h
    in C which is named cstdio (without the extension) for use
    with C++.

    Quote>what is "using namespace std;" , what does it do?

    It puts all code in the std namespace.

    Quote>what is namespace?

    Read this:

    http://www.cprogramming.com/tutorial/namespaces.html


    Quote>do you know of an free online book

    Some tutorials:

    http://www.cprogramming.com/tutorial.html
    http://www.cplusplus.com/
    http://www.parashift.com/c++-faq-lite/
    http://www.research.att.com/~bs/bs_faq.html
    http://cpp.snippets.org/code/ptrtutor.txt

    Some e-books:

    http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

    http://en.wikibooks.org


    - Wayne





    Saturday, December 13, 2008 11:15 PM
  • I have the same problem and as you said I have double checked my spelling and punctuation, although I knew they were right.. but still getting the same error message.
    Friday, May 20, 2011 10:00 PM
  • >I have the same problem and as you said I have double
    >checked my spelling and punctuation ...
    >... but still getting the same error message.

    Rather than tacking this onto the end of a thread which is
    two and a half years old and already marked as "Answered",
    you should start a new thread. But you need to be far more
    specific:

    *Exactly* what error message(s) are you getting? Use copy and
    paste to include the actual message(s) in a post in a new
    thread, and show the line(s) of code which caused the
    error(s).

    - Wayne
    Friday, May 20, 2011 10:29 PM