Starting C++ in VS - Build succeded but no output
Coming from web development I have been trying to get familiar with compiled programming, specifically C++. I usually run into issues like this and end up getting frustrated and putting it off for another month. Hopefully this is something simple.
I used a basic Hello World script:
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
开发者_StackOverflow社区Which when I build I get the following with no "Hello World" output:
1>------ Build started: Project: Hello World, Configuration: Debug Win32 ------
1>Build started 3/29/2011 10:17:23 AM.
1>PrepareForBuild:
1> Creating directory "c:\users\jeff\documents\visual studio 2010\Projects\Hello World\Debug\".
1>InitializeBuildStatus:
1> Creating "Debug\Hello World.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> HelloWorld.cpp
1>LinkEmbedManifest:
1> Hello World.vcxproj -> c:\users\jeff\documents\visual studio 2010\Projects\Hello World\Debug\Hello World.exe
1>FinalizeBuildStatus:
1> Deleting file "Debug\Hello World.unsuccessfulbuild".
1> Touching "Debug\Hello World.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:01.47
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Which seems like it should be working :/
EDIT: :( Of course I just needed to run it. Should the cmd stay open? It just flashes away for me and I get this in my output:
'Hello World.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'Hello World.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'Hello World.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
EDIT 2: Adding cin.get(); has it displaying now, thanks guys...I'm sure it won't be long before I'm back
Place cin.get();
before the return 0
statement. That should let you see the output.
Or navigate to the directory of the executable from Command Prompt and run the Exe.
Or click on the green button where it says Debug
, that should do the job as well.
'Hello World.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
This is normal. It's telling you you don't have symbols installed for the system libraries. This isn't a problem, you can still debug your own code.
Debug--> Options and Settings --> Debugging --> Symbols
In this case it looks like you have built the program but haven't actually run it. Click the green play button and you will likely see a command prompt flash with the output "Hello, World!"
It's so simple. Simply write system ("pause")
before return 0;
code.
精彩评论