C++ 无法打开头文件stdafx.h

d:\vc++6.0\microsoftvisualstudio\myprojects\ad\pont.cpp(1):fatalerrorC1083:Cannotopen... d:\vc++6.0\microsoft visual studio\myprojects\ad\pont.cpp(1) : fatal error C1083: Cannot open include file: 'STDAFX.H': No such file or directory
执行 cl.exe 时出错
#include "stdafx.h"
enum lnstanceState{CLOSE=1,OPEN,MOUNT=4,UNMOUNT};//定义数据库的状态
void opt(lnstancestate state)
{
switch (state)
{
case CLOSE:
{
printf("打开数据库\n");
break;
}
case open:
{
printf("关闭数据库\n");
}
}
}
void main()
{
lnstanceState state=CLOSE;
opt(state);
}
展开
 我来答
百度网友6fe74e2
推荐于2017-09-06 · TA获得超过6593个赞
知道大有可为答主
回答量:1973
采纳率:100%
帮助的人:262万
展开全部

有的版本的VS没有stdafx.h这个头文件,相应的头文件是afx.h

你把

#include "stdafx.h"

改成

#include "afx.h"

应该就行了。

另外你的代码还有问题,完整修改如下:

#include "afx.h"

enum lnstanceState{CLOSE=1,OPEN,MOUNT=4,UNMOUNT};//定义数据库的状态

void opt(lnstanceState state) //这儿Instancestate

{

 switch (state)

 {

 case CLOSE:

  {

   printf("打开数据库\n");

   break;

  }

 case OPEN://open

  {

   printf("关闭数据库\n");

  }

 }

}

void main()

{

 lnstanceState state=CLOSE;

 opt(state);

}

 

结果:

追问
改完后错的更多了
d:\vc++6.0\microsoft visual studio\myprojects\ad\pont.cpp(3) : error C2065: 'lnstancestate' : undeclared identifier
d:\vc++6.0\microsoft visual studio\myprojects\ad\pont.cpp(3) : error C2146: syntax error : missing ')' before identifier 'state'
.......
追答
刚才我正在补充,你代码还有两个地方错误。
#include "afx.h"
enum lnstanceState{CLOSE=1,OPEN,MOUNT=4,UNMOUNT};//定义数据库的状态
void opt(lnstanceState state) //这儿Instancestate
{
switch (state)
{
case CLOSE:
{
printf("打开数据库\n");
break;
}
case OPEN://open
{
printf("关闭数据库\n");
}
}
}
void main()
{
lnstanceState state=CLOSE;
opt(state);
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式