C++程序设计中的问题
我有这个档案。我正试图在visual Studio 2010中运行它。但是它总是给我一个错误,说我需要包含头文件stdafx.h。但是在头文件列表中找不到该文件C++程序设计中的问题,c++,C++,我有这个档案。我正试图在visual Studio 2010中运行它。但是它总是给我一个错误,说我需要包含头文件stdafx.h。但是在头文件列表中找不到该文件 #include <cstdio> #include <cstdlib> #include <iostream> using namespace std; int choice(); double cylinder_volume(); double cone_volume(); double sp
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int choice();
double cylinder_volume();
double cone_volume();
double sphere_volume();
void display_result(double volume);
int main ()
{
int option;
double volume;
option=choice();
if (option==1)
{
volume=cylinder_volume();
display_result(volume);
}
else
if (option==2)
{
volume=cone_volume();
display_result(volume);
}
else
if (option==3)
{
volume=sphere_volume();
display_result(volume);
}
return 0;
}
int choice()
{
int option;
cout<<"What would you like to calculate the volume of: ";
cout<<"\nPress 1 for cylinder. ";
cout<<"\nPress 2 for cone. ";
cout<<"\nPress 3 for sphere. ";
cin>>option;
return option;
}
double cylinder_volume()
{
const double pi=3.14159;
double height,radius,volume;
cout<<"Enter the height of the cylinder: ";
cin>>height;
cout<<"\nEnter the radius of the cylinder: ";
cin>>radius;
volume=pi*radius*radius*height;
return volume;
}
double cone_volume()
{
const double pi=3.14159;
double height,radius,volume;
cout<<"Enter the height of the cone: ";
cin>>height;
cout<<"\nEnter the radius of the cone: ";
cin>>radius;
volume=(1/3)*pi*radius*radius*height;
return volume;
}
double sphere_volume()
{
const double pi=3.14159;
double radius,volume;
cout<<"\nEnter the radius of the sphere: ";
cin>>radius;
volume=(4/3)*pi*radius*radius*radius;
return volume;
}
void display_result(double volume)
{
cout<<volume;
}
这是因为msvc在默认情况下使用预编译头,它的名称为stdafx.h。您应该转到Project->Properties,然后转到C++->Precompiled header并选择不使用Precompiled header。下次创建新项目时,您可能希望取消选中“项目创建向导”中的“使用预编译标题”复选框。这可能意味着要为其编写一条include语句,可能需要先阅读,标题的stdafx.h是-1!更改标题/重新标记以获得更具体的信息,也许?!?我遇到了这个问题,我知道回答一个20年前的问题不会有帮助,但它可能会帮助任何面临同样问题的人。我已经修改了代码,并在Visual C++ 2010 Express和Visual Studio 2015社区中进行了测试,它的工作方式很有魅力。我正在附加下载链接: