错误是: 1> MSVCRTD.lib(crtexew.obj):错误LNK2019:函数_ _tmainCRTStartup中引用的未解析的外部符号 WinMain @ 16 它也给了我这个错误 致命错误LNK1120:1个未解析的外部
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct student
{
string name;
string department;
double first;
double second;
};
class CS112Section
{
student stu[30];
int numOfStudent;
public:
CS112Section();
~CS112Section();
void printSection();
void insert(student student);
int getNumOfStudent();
string MaxFirstAndSecond();
void Average(double&, double&);
bool isFull();
bool isEmpty();
void AddBounsFirst(int);
};
void main()
{
CS112Section section;
char choice;
bool finish = true;
while (finish != false)
{
cout << "1-Insert Info From .Txt file.\n2-Insert Student Manually.\n3-Show The Number Of Student In The Class.\n";
cout << "4-Print The Content Of The Section.\n5-The Student With The Full Marks First And Second.\n6-Show If";
cout << " The Class Full Or Not.\n7-Print The Average Of The First And The Second.\n8-Do You Want To Add Bouns ?\n";
cout << "9-Exit.";
cin >> choice;
switch (choice)
{
case 1:
case 2:
case 3:
cout << "The Number Of Student In The Section : " << section.getNumOfStudent();
case 4:
section.printSection();
case 5:
section.MaxFirstAndSecond();
case 6:
if (section.isEmpty() == 1)
cout << "The Class Is Empty\n";
else if (section.isFull() == 1)
cout << "The Class Is Full";
case 7:
double avF, avS;
section.Average(avF, avS);
cout << "The Average Of The First Is : " << avF;
cout << "\nThe Average Of The Section Is : " << avS << endl;
case 8:
int x;
cout << "How Many Marks Do You Want To Add ?";
cin >> x;
section.AddBounsFirst(x);
case 9:
finish = false;
}
}
}
CS112Section::CS112Section(){ numOfStudent = 0; }
CS112Section::~CS112Section(){ cout << "Good Luck In Your Final ^_^"; }
void CS112Section::printSection()
{
cout << "the Number Of Student In The Section is : "<<numOfStudent;
cout << "---------------------------------------------";
cout << "Name\tFirst\tSecond\tDepartment\n";
for (int i = 0; i < 30; i++)
cout << stu[i].name << "\t" << stu[i].first << "\t" << stu[i].second << "\t"<<stu[i].department << "\n";
}
void CS112Section::insert(student student)
{
for (int i = 0; i < 30;i++)
if (stu[i].name.empty() == 1 && stu[i].first == stu[i].department.npos&&stu[i].second == stu[i].department.npos&&stu[i].department.empty() == 1)
stu[i] = student;
}
int CS112Section::getNumOfStudent()
{
return numOfStudent;
}
string CS112Section::MaxFirstAndSecond()
{
for (int i = 0; i < 30; i++)
if (stu[i].first == 30 && stu[i].second == 30)
return stu[i].name;
}
void CS112Section::Average(double&avF, double&avS)
{
double sumF = 0, sumS = 0;
for (int i = 0; i < 30; i++)
{
sumF += stu[i].first;
sumS += stu[i].second;
}
for (int i = 0; i < 30; i++)
{
if (stu[i].first == stu[i].department.npos)
sumF = 0;
if (stu[i].second == stu[i].department.npos)
sumS = 0;
}
avF = sumF / 30;
avS = sumS / 30;
}
bool CS112Section::isFull()
{
if (numOfStudent == 30)
return 1;
return 0;
}
bool CS112Section::isEmpty()
{
if (numOfStudent == 0)
return 1;
return 0;
}
void CS112Section::AddBounsFirst(int Bouns)
{
for (int i = 0; i < 30; i++)
stu[i].first += 1;
}
答案 0 :(得分:2)
在这种情况下,您似乎已经使用Visual Studio创建了一个Windows应用程序,您打算在其中创建一个控制台应用程序。对于Windows项目,请参阅WinMain entry point - 使用WinMain
代替main
。
要修复它,您需要重新创建项目,选择正确的类型。