链接器问题再次出现

Linker Trouble once more

本文关键字:问题 链接      更新时间:2023-10-16

嗨,我一直在尝试 2 个小时试图找到这些错误的原因:

错误

1 错误 LNK2019:函数___tmainCRTStartup中引用未解析的外部符号_main
错误 2 错误 LNK1120:1 个未解析的外部

它在控制台设置上,

我检查了子系统,它也在控制台上设置。我不知道怎么了,我也是新手C++所以慢慢解释(请)

#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
int Range1, Range2, Guess, Midpoint, NumOfGuess;
string Selection;
bool GameQuit = false;
void MidpointReset()
{
    Midpoint = rand() % 31 + 0;
    Range1 = rand() % Midpoint + 0;
    Range2 = rand() % 31 + Midpoint;
}
void RangeReset()
{
    Range1 = rand() % Midpoint + Range1;
    Range2 = rand() % Range2 + Midpoint;
}
int Main()
{
    MidpointReset();
    while (GameQuit == false)
    {
        cout << "1. Show me the range" << endl
            << "2. I want to guess the number" << endl
            << "3. Quit" << endl
            << "4. Reset MidPoint"
            << "Enter your selection :" << endl;
        cin >> Selection;
        if (Selection == string("1"))
        {
            cout << "Between " << Range1 << " and " << Range2 << endl;
            RangeReset();
        }
        else if (Selection == string("2"))
        {
            cout << "Enter your guess:" << endl;
            cin >> Guess;
            NumOfGuess += 1;
            if (Guess == Midpoint)
            {
                cout << endl << "Right! It took you " << NumOfGuess << " trials!";
                GameQuit = true;
                break;
            }
        }
        else if (Selection == string("3"))
        {
            MidpointReset();
        }
        else if (Selection == string("4"))
        {
            cout << "Thanks for playing!";
            GameQuit = true;
            break;
        }
        else
        {
            cout << "Sorry " << Selection << "Is a invalid selection";
        }
    }
    cout << "Please press any key to exit...";
    _getch();
    return 0;
}

写在main()中很重要

Main()切换到main()以找到入口点。

作为旁注:

cout << "1. Show me the range" << endl
        << "2. I want to guess the number" << endl
        << "3. Quit" << endl
        << "4. Reset MidPoint"
        << "Enter your selection :" << endl;
....
else if (Selection == string("3"))
{
    MidpointReset();
}
else if (Selection == string("4"))
{
    cout << "Thanks for playing!";
    GameQuit = true;
    break;
}
3

和 4 在帮助选择中交换:4 退出,3 重置中点。