Thread: Including iostream.h

  1. #1
    DvdHeijden
    Guest

    Including iostream.h

    I'm completly new to C++, downloaded it today, and have a problem: getting started. I tried a little tutorial first and copied this code:
    Code:
    // my first program in C++
    
    #include <iostream.h>
    
    int main ()
    {
      cout << "Hello World!";
      return 0;
    }
    in the Source Files > test.cpp window. Then I pressed F5 and got this error report:
    ------ Build started: Project: Test, Configuration: Debug Win32 ------
    Compiling...
    test.cpp
    test.cpp(3) : fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory
    Build log was saved at "file://c:\Dominique\Visual Studio\Projects\Test\Test\Debug\BuildLog.htm"
    Test - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    As you see the problem is that iostream.h doesn't exist. How can I get it? Is it part of a compiler or something? I use Visual C++ 2005 Express Beta.

    Regards,
    DvdHeijden

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    The latest C++ standard dictates that you remove the .h extension from all header files, and for files also standard in C, you precede the file name with 'c'. Then you, need to specify the name space you are using. There are several different ways of doing this, personally, I find the best method is to simply add the line, "using namespace std;" after my #include's. This should fix the problem - you'll find compilers will react different depending on when they were released.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
      cout << "Hello World!";
      return 0;
    }

  3. #3
    DvdHeijden
    Guest
    Thanks! It works... But the program closes immidately. What's the code for 'sleeping' or waiting for a key? And it starts in a command line window, how can you edit it so it's in a 'normal' window?

    DvdHeijden

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    It's in the FAQ
    http://faq.cprogramming.com
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    DvdHeijden
    Guest
    Okay, I'll just check FAQ's before asking these questions from now on.

    DvdHeijden]

  6. #6
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    And it starts in a command line window, how can you edit it so it's in a 'normal' window?
    You are writing console based apps, thats why the console window (command line window) opens when you run your program. You aren't doing anything wrong here, thats what the majority of the sample programs are written in. It allows you to focus on learning the language without having to worry about the windows API.


    I hope you have fun learning the language and feel free to post your questions so we can help you out along the way. Just mind
    the forum guidelines

    Happy Coding!!
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    To manage Windows programs, you'll need to learn the Windows API, or one of it's many wrappers. It's quite complicated and requires a pretty good knowledge of C/C++. Just keep learning the tutorials, and when you're done with those, check out Forger's Tutorial. It's one of the best I've seen - just google and you should find a copy.

  8. #8
    DvdHeijden
    Guest
    Yeah, I heard about API. I'm just going to practise 'easy' things in C++, console based. When I know all the basic stuff I will switch to something harder. Another thing: I think I'll make this my 'standard forum' for asking C++ related questions. I like it here .

    DvdHeijden

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Including extra .cpp files visual2008
    By Cathalo in forum C++ Programming
    Replies: 9
    Last Post: 06-16-2009, 03:29 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Class files including other classes
    By combatdave in forum C++ Programming
    Replies: 7
    Last Post: 11-04-2006, 12:37 AM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. Reading a line including blanks
    By Ec4U2du in forum C++ Programming
    Replies: 4
    Last Post: 11-13-2002, 07:32 PM