zoukankan      html  css  js  c++  java
  • C++中vector小学习,顺便查了下<stdio.h>(或<cstdio>)

    今天看书,邻桌在看《C++ Primer》,拿过来看了一会儿。以前比较少用vector容器,看了下后,瞬间觉得好腻害的样子,就想试一下。嗯,就是试一下而已。(代码可能网上都差不多,有参考)

    #include<iostream>
    #include<vector>        //使用vector容器
    #include<string>
    
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        vector<int> TestInt;    //定义一个空的vector实例,int类型
        for (int i = 0; i < 5; i++)
        {
            TestInt.push_back(i);    //向TestInt中添加数值
        }
        for (int i = 0; i < TestInt.size() ; i++)
        {
            cout << TestInt[i] + 1 << endl;        //“[ ]”在vector模板类中被重载
        }
        /*    额,说到这里,看书上后来说还可以用迭代器iterator进行地址访问。好吧,后续了    */    
        
        //下面来学习二维数组的vector使用
        vector<vector<int>> ArrayInt(3, vector<int>(0));    //这里可以注意一下
        
        int i = 0, j = 0;
        for ( i = 0; i < 3; i++)
        {
            for ( j = 0; j < 3; j++)
            {
                ArrayInt[i].push_back(j);
            }
        }
        for (i = 0; i < 3; i++)
        {
            for (j = 0; j < ArrayInt[i].size() ; j++)
            {
                cout << ArrayInt[i][j] << " ";
            }
            cout << endl;
        }
    
        return 0;
    }

    =================================================================

    stdio 就是指 “standard input & output"(标准输入与输出)。在C++中被继承,被规范统一为<cstdio>

    C语言为文件输入输出提供了许多标准库函数。这些库函数构成了C标准库文件<stdio.h>的主体。

    多数与C语言输入输出相关的函数在<stdio.h>中定义。如文件访问:fopen、fclose,二进制读写fread、fwrite,格式化输入输出scanf、printf等。

    (意思就是说,在头文件声明的时候加上它,就可以直接调用一些,C/C++本身内部已经存在的那些标准I/O函数了)

    太晚了,该马上睡了。明天还要早起~^_^~

    I can
  • 相关阅读:
    SCILAB简介[z]
    UG OPEN API编程基础 2约定及编程初步
    Office 2003与Office 2010不能共存的解决方案
    UG OPEN API 编程基础 3用户界面接口
    NewtonRaphson method
    UG OPEN API编程基础 13MenuScript应用
    UG OPEN API编程基础 14API、UIStyler及MenuScript联合开发
    UG OPEN API编程基础 4部件文件的相关操作
    UG OPEN API编程基础 1概述
    16 UG Open的MFC应用
  • 原文地址:https://www.cnblogs.com/leonwen/p/3945918.html
Copyright © 2011-2022 走看看