amateur code not working. any ideas?

i have wrote my "Hello World" code but now want it to stall afta being decoded so that command prompt exit when you press a key. i have used the following to try and do it but it doesnt seem to be working:

#include <iostream>
using namespace std;

int main()
{
cout<<"Hello World";
cout<<"Press any key to destroy the World mwhahaha!";
system ("PAUSE");//this line doesnt seem to work
return 0;
}
Try cin.ignore( 256, '\n' ); instead

or, if you want to get any key input use kbhit() from conio.h
Last edited on
i have inputted that instead of system ("PA...... and it still brings up an error message. it says; unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Which template did you choose when you created that project?

( If you are using VC++ you sould start from Empty Project without clr or anything )
Last edited on
I think that was the reason it wasnt working but i just copied and pasted a code from the variables tutorials into VC++ and it doesnt let that run. it says the same error message again:S
On my VC++ works fine...
Try to #include "stdafx.h" ( if you don't have stdafx.h, just create it as empty file )
Try this:

#include <iostream>
using namespace std;
1
2
3
4
5
6
int main()
{
cout<<"Hello World";
cout<<"Press any key to destroy the World mwhahaha!";
cin.get();
}


Cin.get() will wait for an input from the user before closing.
See, here's the problem with VC++: The default project configuration sucks balls. You can either create a new empty project or do this:
Go to project properties (right click on the project, at the bottom), C/C++>Precompiled Headers>Create/Use Precompiled Header>Not Using Precompiled Header.
Now remove everything from the project that isn't the main .cpp.

That should do it.
Topic archived. No new replies allowed.