C++问题 高手帮帮我

来源:百度知道 编辑:UC知道 时间:2024/06/10 13:41:24
刚学C++,下面的程序有啥错误啊,帮帮我:

#include <StdAfx.h>
int main (void)
{
int num:
num = 1;

printf ("I am a simple");
printf ("computer.\n");
printf ("My favorite number is %d because it is first.\n", num);
return 0;
}
非常感谢大家的帮助,可是我试了都没用,我刚学C++…
头文件绝对是(StdAfx.h);
Header Files(头文件)…
StdAfx.h (软件里就是这样显示的)
这个程序,我照书上照抄下来的。
大家告诉我我有没有格式错误
如果能解决的话就更好了
(我用的是 Visual c++6.0);

下面是错误代码

--------------------Configuration: c1 - Win32 Debug--------------------
Compiling...
first.c
d:\program files\microsoft visual studio\myprojects\zada\java1\first.c(4) : fatal error C1853: 'Debug/c1.pch' is not a precompiled header file created with this compiler
执行 cl.exe 时出错.

first.obj - 1 error(s), 0 warning(s)

程序看起来没什么问题,只是C++ 一般不这么写程序,好好看看书吧,这明显是c的,看你的编译器支持不支持这种写法了,你要把错误是什么发过来更好解决
明显在说你的头文件不对,改下吧

在 include stdafx那下一行写上
#include <stdio.h>

rebuild , rebuild都不行的话就去掉预编译头文件的选项算了

#include <StdAfx.h>
都小写,stdafx.h

对了 是头文件
还有 你是在什么编译环境下编译这个代码的呢
有的C++编译器需要特殊的方式处理C函数
试着将头文件改一下吧

是vc还是的dc啊?

你建的工程有问题吧,试着建一个空的控制台应用程序,然后添加.cpp文件
输入:
#include <stdio.h>
int main (void)
{
int num:
num = 1;

printf ("I am a simple");
printf ("computer.\n");
printf ("My favorite number is %d because it is first.\n", num);
return 0;
}
就好了。
然而这确实是C程序,多看下书吧。