Trying to Run Hello world

Started by
6 comments, last by jbadams 14 years, 9 months ago
I'm reading How to program in C++ 6e by deitel. I was using dev-c++ but on a previous post people recommended i switch to vc++. So i did, i have now installed VC++. The book doesn't take me through how to compile a source code in vc++. and i thought it's because is intuitive. However i've been playing around with VC++ 2005 express edition and i cannot figure out how to run my hello world file. I created a new txt file with notepad. Re-named to hw.cpp and inside saved the following(saved it through notepad). #include <iostream> int main() { std::cout<<"hello world"; return 0; } closed notepad and double clicked hw.cpp to open it with vc++. Someone please let me know what do i do next? there is not button in VC++ IDE enabled that i can "RUN" this file. Thank you C++ newbie
Advertisement
You want "start debug" from the debug menu.

There should be a small green arrow at the top of your window, this will also start it.
You need to create a new, blank, project in VS.
From there, on the solution pane (usually on the left) add your source .cpp file to the project.
Then you should be able to compile and run it. F7 for just a compile. F5 for a compile and run in the debugger.
Yes, unlukily you need a solution even if you just want to compile a simple example taken from a book. I don't remember how dev-C++ worked, but if it gave you the option to compuile a simple file, then you could consider to use it again.
That said, there is no much point in creating a file with notepad when you have VC++ installed :-)

Anyway, once you have your solution and your source files, you have the 'Build' and 'Debug' menus. Here you can compile and run (both in debugging mode and not) you application.
In case you need help with all that, here is some step by step stuff. (I Personally would just use VC++ to create the cpp file, but that's just me)

1: Open up VC++
2: File->New->Project
3: In project types, just click on VC++, rather than all of the sublevels
4: Click emptyproj
5: Type in a name under, you guessed it, name. :P
6: In the menu at the top (A few over from File): Project-Add Existing Item
7: Navigate to your hw.cpp file
8: Click Add
9: In the menu at the top: Build-Build *Your project name here*
10: Debug->Start without debugging, or navigate to the directory where VC++ exports the exe. (Usually it is in C:\Users\name\Documents\Visual C++ versionhere\Projects\projectname, or something similar(That is on vista))


Good luck, and welcome to the wonderful world of game development. Don't be afraid to ask questions. We don't bite. (Generally speaking. We do make exceptions. ;P)
Yay!! thank you guys.
Everyone seems so friendly here :)
As you can probably guess it's actually much easier to work solely within Visual Studio from the start. I imagine a lot of the time you can just reuse and recycle a single project over and over for each example in the book that you want to try out, just by deleting the code and starting again each time.

Alternatively you might want to make a new project for each example, I can't remember how VC++2005 works but if it's the same as 2008 then when you make a new console project you'll be presented with a new project wizard from which I recommend you turn off pre-compiled headers (you don't need them and they're only confusing to beginners) as well as opting to create a blank project (otherwise VS will auto-generate some code that any sensible C++ programmer would surely delete), with a blank project all you have to do is make some new files (.cpp and/or .h) and type the code directly in there.
I know the question has already been answered, but just in case you're still having difficulties, or for the benefit of anyone else who stumbles upon this thread, Josh Petrie has a good little write up on How To: Create A Blank C++ Project In Visual Studio that may be worth a look.

If you're still just getting started with using these tools you may very soon also be interested in How To: Keep Your Console Window Open.

- Jason Astle-Adams

This topic is closed to new replies.

Advertisement