Click here to Skip to main content
16,022,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
G'day...

a bit stumped on this one...

Error In visual Studio 2019 ENT

error CS5001: Program does not contain a static 'Main' method suitable for an entry point


Tried :

[STAThread]
public int static Main(int argc, char **argv)
{


Dunno.... any ideas ?

What I have tried:

[STAThread]
public int static Main(int argc, char **argv)
{
Posted

That error is a C# compiler error but your question is tagged C++ 14. The compiler is saying that it cannot find a suitable entry point for the program.

In C#, the Main method must be static and should have one of the following signatures:

C#
public static void Main()
public static void Main(string[] args)
public static int Main()
public static int Main(string[] args)
Your code snippet seems to be a mix of C# and C++ syntax. In C# it should be more like this :

C#
using System;

class Program
{
    [STAThread]
    public static int Main(string[] args)
    {
        // Your code here
        Console.WriteLine("Hello, World!");
        return 0;
    }
}
If you're working with C++, the entry point should be int main(int argc, char **argv) without the [STAThread] attribute, which is specific to C# :

C++
#include <iostream>

int main(int argc, char **argv)
{
    // Your code here
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

M
 
Share this answer
 
v2
Comments
CPallini 30-Jul-24 7:57am    
5.
M-Badger 30-Jul-24 8:41am    
tx
You have flagged your question C++14, but that code, and the error message, looks like C#.
In C# Main should be:
C#
[STAThread]
static void Main(string[] args)

In C++ main should be:
C++
int main(int argc, char* argv[])
 
Share this answer
 
Comments
CPallini 30-Jul-24 7:57am    
5.
[no name] 30-Jul-24 8:34am    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900