#include "stdafx.h"#include <iostream>
#include <stdio.h>
using namespace std;
int main(void)
{
int age;
printf("--电影购票--\n");
printf("请输入您的年龄: ");
scanf_s("%d",&age);
printf("您要购买的是%s! ^_^\n",age>=60?"优惠票":(0<=age&&age<=12 ? "儿童票":"成人票"));
return 0;
}
最近装了一个VS2008重新学习C++ ,以前和没学一样现在大三,看了一些前辈的帖子 向他们学习,下面是正题:
1)针对上面的代码,VS会自动生成框架 并且有头文件"stdafx.h","stdafx.h"是干什么的?
2)上面若去掉#include <iostream>则编译会不成功,为什么 ?
谢谢大家

解决方案 »

  1.   

    stdafx.h是预编译头。你把编译错误的地方贴出来看看。
      

  2.   

    1. 预编译头文件,包含vc的一些预先编译的信息,编译器帮你自动添加
    2. 包含了一些io相关的定义,去掉,就无法获取定义
      

  3.   

    1>正在编译...
    1>20100507.cpp
    1>c:\users\guochuan\documents\visual studio 2008\projects\20100507\20100507\20100507.cpp(8) : error C2871: “std”: 具有该名称的命名空间不存在
    1>生成日志保存在“file://c:\Users\guochuan\Documents\Visual Studio 2008\Projects\20100507\20100507\Debug\BuildLog.htm”
    1>20100507 - 1 个错误,0 个警告
    ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
    谢谢!您真好
      

  4.   

    #include <iostream> 有没有包含...
      

  5.   

    没有 包含  #include <iostream>   若包含就是正确的    为什么“stdio.h”不行?
      

  6.   

    #include<iostream>
    using namespace std;
    如去掉的话,同时去掉。