Jump to content
  • Advertisement
Sign in to follow this  
sneaky_squirrel

Simple C++ question

This topic is 3732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What do I have to do to find errors? It says It couldn't compile a program because it had an error, but it wouldn;t indicate which line carried the error, and I find no go to line option to find it, I see nothing wrong with the program. I might as well copy paste it, it is the simplest program ever:
#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
  return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by sneaky_squirrel
... it had an error, but it wouldn;t indicate which line carried the error, and I find no go to line option to find it


Sounds like a linker problem. The most common mistake would be to create a win32 project, instead of a console program (was my first mistake in C++ [smile]). Go to File->New->Project..., then locate "Win32 console application", fill in your project name and etc, click finish, then click "empty project" under "application settings" in the next dialog.

For further explanation, a win32 project looks for a WinMain entry, instead of a main.

Share this post


Link to post
Share on other sites
It compiles for me, but you generally don't put a space between a function name and the left parenthesis. And if you are using Microsoft Visual Studio, did you create an empty project?

Share this post


Link to post
Share on other sites
Some compilers require that you add parameters to the main function so replace this line

int main()

with

int main (int argc, char *argv[])

Share this post


Link to post
Share on other sites
Quote:
Original post by Googol PL3X
Some compilers require that you add parameters to the main function so replace this line

int main()

with

int main (int argc, char *argv[])


Which ones? Every compiler I've ever used seems to turn off parameter checking for main(). IIRC, the standard is quite lax about what is required here.

Quote:
Original post by Googol PL3X
but it wouldn;t indicate which line carried the error


If that is the case, _fastcall has the correct diagnosis. I'd agree that the most likely cause was creating a Win32 rather than console project.

Listen to Spoonbender. Post the error. It'll be solved in seconds.

Share this post


Link to post
Share on other sites
Some compilers also require you to put the full name of the header file. Instead of this: #include <iostream>
you put this: #include <iostream.h>

I recommend trying yo compile this way and then if it does not work try ading the args to the main function. Also if your IDE requires you to have any aditional code or format you should use it.
You can look for a simple helloworld in internet that has proven to work in your compiler via entering "Hello World in <your IDE name>"

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!