C++标准

void main(){
   typedef struct {
     int int_field;
     char char_field;
   } my_struct;

  my_struct my_s;
  my_s.int_field=3;  //结构运算符访问结构成员
  my_struct *s;
  s=(my_struct *)malloc (sizeof(my_struct));
  s->int_field=4;//通过指针访问
  s->char_field='a';
  (*s).int_field=6; //通过结构运算符访问
} 

C++标准要求系统提供的头文件不包括后缀.h,例如
iostream、string。为了表示与C语言的头文件有联系又有区别,C++所用的头文
件名是在C语言的相应的头文件名(但不包括后缀.h)之前加一字母c
此外,由于这些函数都是在命名空间std中声明的,因此在程序中要对命名空间std作声明。如
#include <cstdio>
#include <cmath>
using namespace std;
目前所用的大多数C++编译系统既保留了C的用法,又提供了C++的新方法。
下面两种用法等价,可以任选。
C传统方法

#include <stdio.h>
#include <math.h>
#include <string.h>

C++新方法

#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;

可以使用传统的C方法,但应当提倡使用C++的新方法。

posted @ 2015-03-31 12:42  牧 天  阅读(154)  评论(0)    收藏  举报