Results 1 to 8 of 8

Thread: Compile help?VC++

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Compile help?VC++

    okay, im just starting c++(today), can you explain to me how to compile/what im doing wrong here?
    Code:
    #include <iostream.h>
    
    int main()
    {
       cout << "Hello World!\n";
            return 0;
    }
    and it compiled without errors(i pressed the f7 button) and i found a exe file named cpp1.exe,

    when i run it, it looks like a bat file, then closes..without saying anything..

    what am i doing wrong? am i even in the right forum?

  2. #2
    Lively Member
    Join Date
    Jan 2004
    Posts
    82

    Re: Compile help?VC++

    Code:
    #include <iostream> //<iostream.h> is deprecated
    
    int main()
    {
         cout << "Hello World!\n";
         system( "pause" );
         return 0;
    }
    Try this.

  3. #3

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Compile help?VC++

    --------------------Configuration: Cpp1 - Win32 Debug--------------------
    Compiling...
    Cpp1.cpp
    C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(5) : error C2065: 'cout' : undeclared identifier
    C:\Program Files\Microsoft Visual Studio\VC98\Projects\Cpp1.cpp(5) : error C2297: '<<' : illegal, right operand has type 'char [14]'
    Error executing cl.exe.

    Cpp1.exe - 2 error(s), 0 warning(s)

  4. #4

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Compile help?VC++

    Code:
    #include <iostream> //<iostream.h> is deprecated
    #include <iostream.h>
    
    int main()
    {
         cout << "Hello World!\n";
         system( "pause" );
         return 0;
    }
    works perfect, thanks!

    can you explain it at all?

  5. #5
    Lively Member
    Join Date
    Jan 2004
    Posts
    82

    Re: Compile help?VC++

    Code:
    #include <iostream> //<iostream.h> is deprecated
    
    using namespace std;
    
    int main()
    {
         cout << "Hello World!\n";
         system( "pause" );
         return 0;
    }
    Sorry this should work.

  6. #6

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Compile help?VC++

    cool, can you please explain the code, or could someone?

  7. #7
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: Compile help?VC++

    Code:
    #include <iostream> //a header file that's part of the C(++) standard, containing declarations for various functions/types etc. you're gonna use (cout etc.)
    
    using namespace std; //The namespace under which you're working, included here because all declarations in the standard headers are in this namespace
    
    int main() //The program starts at this function, the function returns an int type
    {
         cout << "Hello World!\n"; //Sends the string "hello world!" with a newline char on the end (making a new line) to the console output stream
         system( "pause" ); //Runs the system command pause (causing the press any key to continue text)
         return 0; //returns a 0, indicating the successfull termination of this program
    }
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Compile help?VC++

    Use Firefox or Opera to go here for a very long and thorough breakdown of the Hello application.

    And get rid of the system("pause"). Either invoke the application by pressing Ctrl+F5 in the IDE, or use a console (Run->"cmd") to navigate to the output directory and call the application on the console. In both cases, the console will stay open and you see the output, without adding a non-portable and nonsensical piece of code.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width