Announcement

Collapse
No announcement yet.

n00b: trying to compile 'hello world' in visual studio 2010

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • n00b: trying to compile 'hello world' in visual studio 2010

    im trying to compile the basic 'hello world' in vs2010 and the build icons are greyed out. any reason why?

    #include <iostream.h>

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


    ::edit::

    vs can't seem to find 'iostream.h' file.

    ::edit::

    nevermind the iostream.h. apparently its iostream now. but i still can't build the damn thing. /cry
    Last edited by nivlac; April 24, 2011, 02:05 PM.

    AHD | AT | BCG | BitMe | BTN | CHD | HDB | HD-T | IPT | PEDRO | PTN | PTP | WFL | W.CD

    If nobody hates you, you're doing something wrong.

  • #2
    Re: n00b: trying to compile 'hello world' in visual studio 2010

    You can't compile because the icon is greyed out? I could only imagine two situations this happens:

    - a build is currently running, which is propably not
    - maybe a stupid question: Did you create a project? You can open a cpp file with VS, but you won't be able to compile it, so you need to create a project and include your files in the project


    Edit: I'm not sure if I understood your question. But just detected a mistake. Try this:

    #include <iostream.h>

    using namespace std;

    int main ()
    {
    cout << "Hello World!\n";
    return 0;
    }
    Last edited by Tim; April 25, 2011, 03:18 AM.

    Comment


    • #3
      Re: n00b: trying to compile 'hello world' in visual studio 2010

      I suspect the same as Tim . Did you make a C++ project or are you just trying to compile standalone C++ file.

      If you have not made a project go to File-->New project -->Visual c++ -->empty project.
      Add your .cpp in the project . Now Build should not be greyed out.

      Comment


      • #4
        Re: n00b: trying to compile 'hello world' in visual studio 2010

        Not sure about the whole project thing, but I created a file "hello.cpp" like this:

        #include <iostream>

        using namespace std;

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

        compiled it and ran it. Does cout even work in visual studio? Isnt that command line specific? To be honest, I've only used vs a few times.

        Comment


        • #5
          Re: n00b: trying to compile 'hello world' in visual studio 2010

          Originally posted by nivlac View Post
          nevermind the iostream.h. apparently its iostream now. but i still can't build the damn thing. /cry
          You will encounter situations like these a fair bit in your programming life :) So your first problem was that the compiler couldn't find the header file, because you don't write ".h" for that particular include. You solved that problem yourself, so if it's still not building there must be another error, otherwise you will get "0 errors 0 warnings" in the console window. What is that error?

          Comment


          • #6
            Re: n00b: trying to compile 'hello world' in visual studio 2010

            Originally posted by agent69 View Post
            Not sure about the whole project thing, but I created a file "hello.cpp" like this:

            Does cout even work in visual studio? Isnt that command line specific?
            It surely does. You can also make console applications on Visual Studio , not just GUI based

            Comment


            • #7
              Re: n00b: trying to compile 'hello world' in visual studio 2010

              please follow this step creating project,

              file->new->project
              win32->win32 console application
              wizard->press next
              choose [Console application] & Empty Project!!!

              After thses steps you will have an empty c++ console project.

              Add your cpp file to project and it will compile.

              Comment


              • #8
                Re: n00b: trying to compile 'hello world' in visual studio 2010

                Your code should work in CodeBlocks or DevCpp ( you will need also system("pause") ) , for VS you probably should follow ebirlik's tip.
                Last edited by PROMOTER; June 18, 2011, 07:42 AM.
                EUROPE'S FINEST

                Comment


                • #9
                  Re: n00b: trying to compile 'hello world' in visual studio 2010

                  It's worth noting that as currently written, even if this program compiles, when you run it you won't see the output. In Visual Studio, when you run a console application, it automatically gets closed after it finishes executing. To actually see the "Hello World" outputted, you should add

                  Code:
                  system("pause");
                  to the bottom of your program (just before the "return 0;" line). This is the most common work-around people use, but it's kind of ugly and you shouldn't get in the habit of doing it because it makes your programs not work on other operating systems. You should look at this thread at Microsoft for more information, and for a better work-around (see the last post).

                  Hope this helps.

                  Comment

                  Working...
                  X