zoukankan      html  css  js  c++  java
  • push_back的使用

     push_back   是算法语言里面的一个  函数名。     C++ 中的vector头文件里面就有这个push_back函数,在vector类中作用为在vector尾部加入一个数据。string中也有这个函数,作用是字符串之后插入一个字符。

     1 #include <iostream>
     2 #include <vector>
     3 #include <string>
     4 
     5 using namespace std;
     6 
     7 int main()
     8 
     9 {
    10     vector<int> v1;
    11     v1.push_back(10);
    12     v1.push_back(11);
    13     v1.push_back(12);
    14 
    15     vector<int> v2(v1);
    16 
    17     vector<int> v4(10, 8);
    18     vector<int> v6(8);//输出的是8个0,
    19 
    20     vector<string> v5(8, "xiao cui");
    21     vector<string> v7(9); //输出的是9个空串
    22 
    23     for (vector<int>::size_type i = 0; i != v5.size(); ++i)
    24         cout << v5[i] << endl;
    25 
    26     cout << v1[0] << endl;
    27     cout << v2[0] << endl;
    28     cout << v4[0] << endl;
    29     cout << v5[0] << endl;
    30     cout << v6[0] << endl;
    31     cout << v7[0] << endl;
    32 
    33     v1[0] = 100;
    34     cout << v1[0] << endl;
    35 
    36 
    37     return 0;
    38 }
    View Code

    https://blog.csdn.net/qq_31248551/article/details/50499702

    https://blog.csdn.net/Appleeatingboy/article/details/79195289

  • 相关阅读:
    Servlet Class4
    Servlet Class3
    Servlet Class2
    Servlet Class1
    HTTP基础知识
    XML基础知识
    JAVA Class25
    JAVA Class24
    JAVA Class23
    JAVA Class22
  • 原文地址:https://www.cnblogs.com/thebreakofdawn/p/9501873.html
Copyright © 2011-2022 走看看