
#include <iostream> //用于输入输出 #include <cmath>//用于数学公式计算,例:sum:求和。sqrt:根号。abs:绝对值。pow(2,3)=2的三次方。floor(-2)=-2。 #include<ctime>//引入time 主要用于生成srand,例:srand((unsignde)time(NULL)).这样能使用:int a =rand(); 用于生成随机数 #include <cstdlib>//使用calloc,等等,这是常用的c++函数库,分配空间等等都会用到。 #include <iomanip>// manip:操纵者。使用 setw 有序排列 #include <cstring>//使用char的操作符,例:strlen: 查看字符串的长度 ,strcopy:复制字符串 这些函数是针对与char a[] 的
#include <string>//在c++中存在string,注意是小写,字符串可以相加,例:string a= s+d;a.size();等等
#include <iomanip>//
using std::setw;
int main(){ for (int i=1;i<=100;i++){ cout << setw( 2)<< i<<endl; } return 0;}setw(num);中的num表示所占输入字符的站位;
多维数组:
int main() { int aaa[3][3]={ {1,2,3}, {4,5,6}, {7,8,9} }; cout <<aaa[2][2]; return 0; }
结果是9;int [2][2]:表示两行两列, cout <<aaa[2][2]:表示输出低三行第三列元素。数组是从0开始。
字符串:
int main() { char aa[]="zhangjiqun"; char ss[]={'w','e','4'}; cout<<ss[2]; cout << aa[2]; }
char aa[]="zhangjiqun"; char ss[]={'w','e','4'};这是两种命名的方式,从0开始。
结果是4a第三位,由于字符串的位置也是从0开始的。