Jump to content
BrainDen.com - Brain Teasers
  • 0


Guest
 Share

Question

Okay, so I'm trying to teach myself C++, and I'm copying some code from the book. It's the "Hello World" thing.... it's my first time actually typing in code. I'm using Visual Studio 2010 Express edition, and here's my code:

//1.1-Hello World-Mark Lee

#include <iostream>

int main( void )

{

using std::cout;

cout<<"Hello World!\n";

return 0;

}

When I try to run it (CTRL + F5), a message pops up saying my project is out of date. On the same window it asks me if I want to build it. I say yes.

Then a new window pops up saying "There were build errors. Would you like to continue and run the last successful build?" If I press yes, it pops up saying its unable to start the program because the system is unable to find the program specified.

My output looks like this:

1>------ Build started: Project: Hello World, Configuration: Debug Win32 ------

1> HelloWorld.cpp

1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

1>C:\Users\*******\documents\visual studio 2010\Projects\Hello World\Debug\Hello World.exe : fatal error LNK1120: 1 unresolved externals

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

As I was copying this from the book, like it said, and I haven't actually learned anything yet, I don't know what to look for error-wise. Thanks for any help :)

Edited by NickFleming
Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

Looks like you might not have the project configured correctly. Did you by chance make a windows application instead of a console application?

Link to comment
Share on other sites

  • 0

you declarations at the top are sort of off.

should read:

#include <iostream>

using namespace std;

then you can leave the using line out of the main function.

using that format you should be able to just type "cout<<*Message*;" and "cin>>*variable*;" to output *message* to the user and get *variable* from the user.

so your code file should look like:

#include <iostream>

using namespace std;

int main(void)

{

char a = 0;

cout<<Hello World!;

cin>>a;

return 0;

}

The "cin" line doesn't do anything aside form force the output to stay up until the user hits a key instead of flashing up and going away as soon as the code is finished. Debugging will do that automatically but once you build and run the executable that won't be the case anymore.

Edited by Rien17
Link to comment
Share on other sites

  • 0

...use

#include <iostream>

#include <cstdio>

#include <cstdlib>

using namespace std;

int main()

{

cout << "Your message";

system("pause");

return 0;

}

What I learned to do first. Nick, if you require further assistance in console c++, feel free to PM me. I don't claim to be an expert, but I have several years and several hundred programs under my belt.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...