Log in

View Full Version : C++ Run Issue


JackOfClubs
September 29th, 2010, 06:53 PM
This is driving me insane....

This year in school I'm taking Computer Science I, which is C++. We're supposed to do all of the programs at school, but I figured I might as well play around with it at home. So I downloaded Microsoft Visual C++ Express 2010, figuring that it would work. We have Microsoft Visual C++ 6.0 in school (I know its prehistoric but...), and I thought that if it works in school it'll have to work here, as my laptop is only a lot better than the crap-boxes they have there.

Anyway... whenever I try to run a program, the terminal screen pops up, but then immediately disappears. Just to show you the problem, and that it works on codepad.org (http://codepad.org/W8uOmzqn), I made a video. You'll probably have to go to YouTube and watch it in 720p to see it clearly.

5caRNKLipqs

Thanks.

And I didn't know that it recorded from the mic, so that clapping is just me playing with the mouse.

Peace God
September 29th, 2010, 07:20 PM
did you put this at the end of your code?
system ("pause");
if not try it and see if it works

edit: ok... i just saw the vid
put the system ("pause"); at the end...and if it notifies you of any errors (2nd pop up) make sure you hit "no" so that you can see what you did wrong

JackOfClubs
September 29th, 2010, 07:29 PM
This is the error result:

1>------ Build started: Project: TEST, Configuration: Debug Win32 ------
1> TEST.cpp
1>c:\users\jack\documents\c++\test\test\test.cpp(3): warning C4627: '#include <iostream.h>': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>c:\users\jack\documents\c++\test\test\test.cpp(13): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

It says iostream was skipped. And we don't have to use StdAfx. And when I added it I still get errors.

Peace God
September 29th, 2010, 07:32 PM
This is the error result:



It says iostream was skipped. And we don't have to use StdAfx. And when I added it I still get errors.
just type <iostream>...not <iostream.h>

JackOfClubs
September 29th, 2010, 07:35 PM
Nothing. Got the same errors as before. Are there any libraries or directories or anything I should download? Just in case...

Peace God
September 29th, 2010, 07:38 PM
oh...and put using namespace std; in the line under #include <iostream>

JackOfClubs
September 29th, 2010, 07:42 PM
Same errors... Maybe I should uninstall and reinstall. Because I can run a command prompt with no problems at all.

Peace God
September 29th, 2010, 07:44 PM
we'll im using Microsoft Visual Studio 2008
and this compiles with no problems...

#include <iostream>
using namespace std;

int main()

{
cout << "LOLZ\n";
system ("pause");
return 0;
}

JackOfClubs
September 29th, 2010, 07:46 PM
For some reason mine isn't.

And I get the following results in the box at the bottom when I hit 'yes' instead of 'no' when it says I have errors (Which are the same)

'TEST.exe': Loaded 'C:\Users\Jack\Documents\C++\TEST\Debug\TEST.exe', Symbols loaded.
'TEST.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
The program '[4380] TEST.exe: Native' has exited with code 0 (0x0).

EDIT:
And yay for Blue Screens...

Peace God
September 29th, 2010, 08:02 PM
i think thats just the "output" box...thats not really an error list

the error list should look like this
http://img411.imageshack.us/img411/9206/51820045.jpg

hitting "yes" will just run the last working code... hitting "no" will stop the compiler and show you the error list

if the error list isnt coming up maybe you have it disabled...check under the "view" tab

JackOfClubs
September 29th, 2010, 08:11 PM
Its there. I must have hit yes instead of no when it asked to run the last successful build.

http://i55.tinypic.com/5ufkes.jpg

CaptainObvious
September 29th, 2010, 08:16 PM
Pre-compiled headers are a compilation technique used to save time on large projects that would otherwise require a massive number of header files to be compiled every compilation.

So, the specific fix here will have something to do with telling VC++ not to use them, probably. Google the error, that's normally the quickest way to figure it out.

But really, this is why new programmers should not be using an IDE like VC++. Its added complexities contribute nothing to your learning experience, and are clearly right now detracting from it.

JackOfClubs
September 29th, 2010, 08:21 PM
OK. I figured that because its what we start off with in school it might be the best option at home, thanks for letting me know.

Are there any compilers you'd recommend?

CaptainObvious
September 29th, 2010, 08:24 PM
There are compilers I'd recommend, yes, but I have a feeling given that you've only used an IDE prior to this that would just waste more of your time. So instead, I'll point you to Dev-C++ (http://www.bloodshed.net/devcpp.html) which is also an IDE (and therefore philosophically, not my favorite for introductory students) but is much simpler.

Specific to MSVC++, though, I'm pretty sure to fix this you would just need to mark "Not Using Precompiled Headers" in the project property file.

Peace God
September 29th, 2010, 08:25 PM
ok when you start projects make sure you check "empty project" instead of "precompiled headers"

http://img838.imageshack.us/img838/214/79936075.jpg

JackOfClubs
September 29th, 2010, 08:34 PM
There are compilers I'd recommend, yes, but I have a feeling given that you've only used an IDE prior to this that would just waste more of your time. So instead, I'll point you to Dev-C++ (http://www.bloodshed.net/devcpp.html) which is also an IDE (and therefore philosophically, not my favorite for introductory students) but is much simpler.

Specific to MSVC++, though, I'm pretty sure to fix this you would just need to mark "Not Using Precompiled Headers" in the project property file.
OK I'll try Dev-C++.

ok when you start projects make sure you check "empty project" instead of "precompiled headers"

[IMG]

OK, so when I do that, I make some progress. I get a different error:
1>------ Build started: Project: TEST2, Configuration: Debug Win32 ------
1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>c:\users\jack\documents\visual studio 2010\Projects\TEST2\Debug\TEST2.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

And using Dev-C++, I'm not getting any errors, but it still won't display. The terminal shows up for a quick flash, I can see that the code worked, but then immediately disappears.

EDIT:
Did a Google. Found that if I use the following code, the window stays open.

cin.ignore(256, '\n');
cout << "Press ENTER to continue..." << endl;
cin.get();

If there is any other way, that would be great. But if there isn't, thanks very much for your help! +rep.

CaptainObvious
September 29th, 2010, 08:54 PM
Think about the logic behind how a program works. When you invoke the executable outside an existing console session, it will only open a terminal window to display what you have printed to standard out; if you have not put anything else there that would require that terminal window to remain open, it will then immediately close. That's what you're seeing.

What you did is one simple solution: it just waits for user input to close. Another simple solution is to invoke the executable from an already-open console session.

But this is why I don't like people teaching with IDEs. You should be learning this stuff systematically before you move on to working with IDEs, not trying to learn it haphazardly to make the IDE work.

Commander Thor
September 29th, 2010, 09:44 PM
EDIT:
Did a Google. Found that if I use the following code, the window stays open.

cin.ignore(256, '\n');
cout << "Press ENTER to continue..." << endl;
cin.get();

If there is any other way, that would be great. But if there isn't, thanks very much for your help! +rep.

Should be able to hit "CTRL+F5" (In Visual Studio) and the console window will stay open.
The program itself will finish, but the console window will stay open with the message of "Press any key to continue...".

JackOfClubs
September 30th, 2010, 08:51 PM
Think about the logic behind how a program works. When you invoke the executable outside an existing console session, it will only open a terminal window to display what you have printed to standard out; if you have not put anything else there that would require that terminal window to remain open, it will then immediately close. That's what you're seeing.

What you did is one simple solution: it just waits for user input to close. Another simple solution is to invoke the executable from an already-open console session.

But this is why I don't like people teaching with IDEs. You should be learning this stuff systematically before you move on to working with IDEs, not trying to learn it haphazardly to make the IDE work.
Oh ok, that makes sense. Its auto-closing because the program is finished running. Gotcha. And we aren't just going straight to the IDE, we actually only use a computer once every one or two weeks. We learn it in class, then the teacher checks the code, then we run it.

Should be able to hit "CTRL+F5" (In Visual Studio) and the console window will stay open.
The program itself will finish, but the console window will stay open with the message of "Press any key to continue...".
No luck. Still getting errors. Such as "cout: undefined identifier" etc.


I believe all this may have something to do with my laptop has pretty new software on it, and the computers in school use VC++ 6.0, and our CompSci book was published in 1998.

CaptainObvious
September 30th, 2010, 08:54 PM
no, the undefined identifier error is because you're doing:

cout << "some random crap" + endl;

without having first done

using namespace std;

without the using directive, you'd need to do

std::cout << "some random crap" + endl;