代码改变世界

C++学习笔记(1)

2011-08-28 22:07  QA龙  阅读(232)  评论(0编辑  收藏  举报

1.编译 先把cpp文件编译
2.组建 把编译好的文件组建成.exe 文件
3 1).iostream 输入输出 头文件
  其中有两个对象
  cout 对象 << 运算符重载 用于输出
  cin  对象 >> 运算符重载 用于输入

  2).cmath 引用原始的c头文件 在其前面加个c 也可用 math.h
    double sqrt(double b) 求平方根的函数
    double pow(double a,double b) 求指数的 函数 pow(2,3) 求2的3次幂是多少
    int rand() 函数 随机函数
  3).climits c头文件 limits.h 的c++版本
  定义了符号常量 用来表示 类型的限制
  4).string 头文件
   定义了 string 类型
4.
  数组中对数组下标错误 感觉处理的挺不好的不好
 #include<iostream>
 #
 int Arr[4] ={1,2,3,4};
 for(int i=0;i<8;i++)
 {
 cout << Arr[i] << endl;
 }
5.Struct结构
 #include<iostream>
 #include<string>
 using namespace std;
 struct Guest
 {
 //string name;//执行失败 error C2552: 'g' : non-aggregates cannot be initialized with initializer list
 char mame[20];换成char 数组 执行成功 为什么 使用string类型不能成功呢?
 int age;
 };
 int main()
 {
 Guest g =
 {
  "QA龙",
  23
 };
 cout << g.name <<endl << g.age <<endl ;
 }
 执行失败
 原因:因为有些编译器(包括Borlandc++ 5.5 和7.0 版以前的Microsoft Visual C++)不支持以string 对象作为成员的结构进行初始化
      可以在结构定义之前 使用using指令 using namespace std; 让结构可以访问std空间
      但是如此以后 还是不能 像数组那样给结构赋值

小弟主要学c# .net 的 刚开始学c++ 老多东西都不知道 请各位大仙多多指导