zoukankan      html  css  js  c++  java
  • c++ vector实例

    #include <iostream> 
    #include <string> 
    #include <vector> 
    #include <iostream> 
    using std::cout;
    using std::cin;
    using std::endl;
    using std::vector;
    using namespace std;
    
    int main() 
    {
        string s = "hell";
        string w = "worl!";
        s = s + w; //s +=w;  
        for (int ii = 0; ii != s.size(); ii++)
        {
            cout << ii << " " << s[ii];
        }
        cout << endl;
    
        string::const_iterator cii;
        int ii = 0;
            for (cii = s.begin(); cii != s.end(); cii++)
        {
            cout << ii++ << " " << *cii << endl;
        }
        
    
    
        vector<double> student_marks;
        
        int num_students;
        cout << "Number of students: " << endl;
        cin >> num_students;    
    
        student_marks.resize(num_students);
    
        for (vector<double>::size_type i = 0; i < num_students; i++) 
        {
            cout << "Enter marks for student #" << i + 1
                << ": " << endl;
            cin >> student_marks[i];
        }
    
        cout << endl;      
        for (vector<double>::iterator it = student_marks.begin();
            it != student_marks.end(); it++) 
        {
            cout << *it << endl;
        }
        
        return 0;
    }  

    0 h1 e2 l3 l4 w5 o6 r7 l8 !
    0 h
    1 e
    2 l
    3 l
    4 w
    5 o
    6 r
    7 l
    8 !
    Number of students:

    3
    Enter marks for student #1:
    3
    Enter marks for student #2:
    2
    Enter marks for student #3:
    6

    3
    2
    6

  • 相关阅读:
    js小程序
    事务的概念
    为期一个月培训的总结
    软件测试培训总结篇2
    软件测试培训总结篇1
    软件测试培训第30天
    软件测试培训第29天
    软件测试培训第28天
    软件测试培训第26天
    软件测试培训第27天
  • 原文地址:https://www.cnblogs.com/CodeWorkerLiMing/p/10998033.html
Copyright © 2011-2022 走看看