-2

I'm very new to c++. I have a standard dev c++ windows application winapi, but it doesnt get formatted well here on stackoverflow. So here you can see it: see here

but my question is, where am i supposed to do the main function? if i just create a new int main(), the window doesn't come up at all. am i supposed to do it in the WinMain() function?

any suggestions?

EDIT: I just found out dev c++ doesnt have a compiler.

Sam
  • 381
  • 3
  • 15
  • 2
    If you're making a console program the entry point is main, if a Windows app it is WinMain. Unless you go out of your way to change the entry point that function is called automatically for you. You should learn to post code here, a link that expires doesn't help anyone looking at this question later. – Retired Ninja Jul 08 '17 at 14:51
  • @RetiredNinja Do I have to create a new function or use the existing one? – Sam Jul 08 '17 at 14:53
  • If you start your programs with an empty file and then write code you'd need to provide the proper function. If you're copy/pasting it depends on what those contents are. – Retired Ninja Jul 08 '17 at 14:54

1 Answers1

3

Notice that Dev-C++ is not a compiler, but an IDE (that is, a glorified source code editor). Your compiler is probably some variant of GCC (a free software compiler) like MINGW.

In standard C99 (or C11) or C++11, the entry point of your (command line) program is main.

You need to define such a function, and the runtime system (e.g. crt0 on Unix) will call it.

You should not call that main function. Its prefered signature should be

int main(int argc, char**argv);

You probably should run your program in some terminal emulator. Here are some properties of argc and argv (imposed by the C or C++ standards).

Any other entry point (e.g. WinMain) could be Windows specific and might require some specific compiler options.

You would compile a C program using gcc, and a C++ program using g++. I strongly recommend enabling all warnings & debug info by using -Wall -Wextra -g flags to that gcc or g++ compiler. You may want to use some build automation tool like GNU make.

For GUI programs in C++, I would recommend Qt (it is free software, and multi-platform).

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • somehow i got him to compile using g++.exe. compiling result: `Compilation results... -------- - Errors: 0 - Warnings: 0 - Output Filename: C:\Users\Sam\Desktop\Project1.exe - Output Size: 1,83782863616943 MiB - Compilation Time: 6,01s ` – Sam Jul 08 '17 at 14:59