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

  • 相关阅读:
    socket套接字 struct模块
    网络编程 OSI七层协议
    内置方法 eval | exec 元类 单例
    选课系统
    iOS清理缓存 2016-04-19
    iOS 蓝牙 技术
    iOS人脸识别
    iOS 指纹识别
    极光推送的初步配置及其使用
    iOS 加急审核
  • 原文地址:https://www.cnblogs.com/CodeWorkerLiMing/p/10998033.html
Copyright © 2011-2022 走看看