main的多个定义,首先在devc++; 我只是一个C++初学者,我使用的是DEVC++。我在一个项目中有两个单独的文件,但当我运行第二个文件时,会显示一条错误消息: test.cpp:(.text+0x0): multiple definition of `main' first defined here).

main的多个定义,首先在devc++; 我只是一个C++初学者,我使用的是DEVC++。我在一个项目中有两个单独的文件,但当我运行第二个文件时,会显示一条错误消息: test.cpp:(.text+0x0): multiple definition of `main' first defined here).,c++,C++,你能详细地给我解释一下怎么改吗 抱歉重复这个问题,因为我不理解。如果已经有任何详细的答案,请提供链接 这是我的两个文件: prblm2.cpp #include<iostream> using namespace std; int main() { const double artificial_sweetner=0.001; double mouse_weight, friend_weight, die, number_of_soda_pop; cout&

你能详细地给我解释一下怎么改吗

抱歉重复这个问题,因为我不理解。如果已经有任何详细的答案,请提供链接

这是我的两个文件:

prblm2.cpp

#include<iostream>
using namespace std;
int main()
{
    const double artificial_sweetner=0.001;
    double mouse_weight, friend_weight, die, number_of_soda_pop; 
    cout<<"type in the weight of the mouse and your freinds target weight"<<endl;
    cin>>mouse_weight>>friend_weight;

    while (mouse_weight>0 && friend_weight>0)
    {
        die=(friend_weight/mouse_weight)*artificial_sweetner;
        number_of_soda_pop=die/artificial_sweetner;
        cout<<"the number of soda your freind can drink is "<<number_of_soda_pop<<endl;
        cout<<"type in the weight of the mouse and your freinds target weight"<<endl;
        cin>>mouse_weight>>friend_weight;
    }

}
#包括
使用名称空间std;
int main()
{
const-double-artificial_-sweetner=0.001;
双倍鼠标重量,朋友重量,模具,苏打汽水数量;
coutfriend_体重;
while(鼠标权重>0&&friend\u权重>0)
{
骰子=(朋友的体重/老鼠的体重)*人造甜食;
苏打水的数量=模具/人造甜味剂;

cout您的问题是您有两个
main
函数。标准不允许这样的程序。解决方法是只使用一个
main

例如:

此程序不正常,因为主功能太少:

void foo(){}
int main(){}
int main(){}
int main(){}
此程序不正常,因为有太多的
main
功能:

void foo(){}
int main(){}
int main(){}
int main(){}
此程序结构良好,具有正确数量的
主要功能:

void foo(){}
int main(){}
int main(){}
int main(){}

你不能有两个主电源…我知道如果我从第二个文件中删除主电源,它就不工作了。我已经否决了这个问题,因为你已经知道答案(“将它放在单独的项目中”),并且没有给出它不工作的原因(“但我不想”几乎不是一个原因)@Dzmitry Kushnarou有时你想让你的文件井然有序,你不想让文件在两个不同的文件之间混在一起projects@Tasif存在用于组织代码的项目。一个项目包含一个程序的代码。如果您正在创建两个程序(这就是您正在做的),您应该创建两个项目。如果这样做,那么我应该从第二个文件中删除main吗。@Tasif您确定它没有运行吗?您是如何验证的?@user207933 C:\Users\User\Documents\C++\prob solving\programming projects\test.cpp[Error]在'for'之前应该有不合格的id我删除了int main()和大括号。@Tasif这不是运行程序的问题。这是一个编译错误。您不能只删除函数原型和大括号。您还必须删除中间的所有行。因此,请告诉我第二个文件的代码将如何,谢谢您的耐心