Back to basics

Started by
11 comments, last by dahmer45 17 years, 11 months ago
I've decided to throw everything I've learned out the window and re learn C++. So ealier today I made a simple hello world program. But when I run it, it shows a black window and crashes.Heres my source code. #include "stdafx.h" // MSVC++ throws a fit if i dont include this #include <iostream> using namespace std; int main() { cout << "Hello World\n"; } Someone please help me.
Advertisement
Hi bud,

Well to begin with i would avoid precompiled headers. When you create the project in Visual Studio, uncheck the precompiled headers box. There is no reason for that to crash otherwise. But what it will do is flash up the console box and then exit immediately.

Dave
Ok, when I make a new project I don't see a precompiled headers box. I only see 'Create directory for solution' box. Also what template should I use?
int main() should return an integer.

#include <iostream>

using namespace std;

int main()
{
cout << "Hello World\n";

return 0;
}

If it appears and disappears right away, try using this:
cin.get();
or this:
system("PAUSE");
right before your return statement. Neither is great, but they work.
Ok I added return 0; but its still doing the same thing.
Quote:Original post by slowmike
If it appears and disappears right away, try using this:
cin.get();
or this:
system("PAUSE");
right before your return statement. Neither is great, but they work.


Quote:Original post by slowmike
int main() should return an integer.
Technically you don't have to
but it's good practice.
F-R-E-D F-R-E-D-B-U-R...G-E-R! - Yes!
What IDE are you using?
Ok I added system("PAUSE") and it works now, thanks guys.

IDE is compiler right?
Yeah, that used to happen to me alot when I had started re learning C++. I am not using SDL for C++. It is pretty cool. Just remember to put in that system("PAUSE"); next time
if(dahmer45 does not enter wat I told him to) {
cout<<"ENTER SYSTEM("PAUSE");\n"; I just had to do that.
cout<<"cout<<'' this is my siggy''";

This topic is closed to new replies.

Advertisement