C++中的一些头文件:template、iostream、vector、stdafx.h、string.h、memcmp、stdio.h、math.h

1.template :函数模板,放在函数定义前面

//
template <typename T>     //对类型进行匹配 
T max(T a,T b)       //函数名和参数前面都有T,对类型进行匹配
{
return a>b?a:b;
}

//比如  int max(int a,int b);

2.template :类模板,定义一个类时放在类的前面,类的成员函数前面

//类模板的使用
template <class T>
class stack{
public:
     void push();  //入栈
     void pop(); //出栈
};

template <class T>     //类的成员函数定义
void stack<T>::push()         //  类::成员函数
{
    elems.push_back();
}

template <class T>
void stack<T>::pop()
{
    elems.pop_back();
}

//派生类(继承)
class temp::public stack{

}

3.#include 输入/输出头文件, iostream 标准库,提供了 cin 和 cout 方法分别用于从标准输入读取流和向标准输出写入流。

4.include vector是向量,也是动态数组,在堆上,比array(数组)更常用。

不需要变长,容量较小用array;需要变长,容量较大用vector。

//
#include <iostream>
#include <vector>
using namespace std;

void main()
{
    std::vector<std:string>string1;   //创建一个字符串数组
    string1.clear();  //清空
    string1.push_back("nate");  //尾部加入一个字符串

   std::vector<int>myvector;//创建一个数组变量,元素是int类型
   myvector.push_back(32);   加入32

   std::vector<std::vector<int>>allvector;//创建一个数组变量,元素就是数组
   allvector.push_back(myvector);

for(int i =0;i<allvector.size();i++);  //遍历
{
  for(int j = 0; j<allvector[i].size();j++)
  {
       std::cout<<allvector[i][j];
  }
       std::cout<<std::endl;          //end line    结束此行
       
}

   system("pause");
}

4.#include"stdafx.h"
Standard Application Frame Extend没有函数库,只是定义了一些环境参数,使得编译出来的程序能在32位的操作系统环境下运行。

5.#include <string.h>
包含一些字符串操作函数的调用。

//strcpy
#include <string.h>
char *strcpy(char *str1,const char*str2);//把字符串str2(包括'\0')拷贝到字符串str1当中,并返回str1
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值