关于C++中vector使用--simple test

来源:互联网 发布:单片机代码工具 编辑:程序博客网 时间:2024/06/16 03:38
#include<vector>#include<iostream>using namespace std;#define LEN_JOB_NUMBER 8typedef struct stuff{    char job_number[LEN_JOB_NUMBER];    int salary;}stuff;char *array_job_number[3] = {"ab010203", "ab010204", "ab010205"};int array_salary[3] = {3000,3500,4000};vector<stuff>department;// department1;vector<stuff>::iterator it_department;//typedef   void (_stdcall *depart_init)(int num_member);vector<int> array_my;vector<int>::iterator it_array_my;void depart_init(int num_member){    stuff stuff_temp;    int i;    char job_number_temp[LEN_JOB_NUMBER+1];    int salary_temp;        for(i=0;i<num_member;i++)    {        cout << i << endl;        //stuff_temp.job_number = new char[LEN_JOB_NUMBER+1];        cout << "please input job number of "<< LEN_JOB_NUMBER << " numbers"<<endl;        //for(j=0;j<LEN_JOB_NUMBER;j++)        //{            cin >> job_number_temp;        //}        cout << "please input salary"<< endl;                cin >> salary_temp;        //stuff stuff_temp;        memcpy(stuff_temp.job_number,job_number_temp,LEN_JOB_NUMBER);        //stuff_temp.job_number = salary_temp;        stuff_temp.salary = salary_temp;        //it_department = department.begin();        //department.insert(it_department,stuff_temp);        //it_department ++;        department.push_back(stuff_temp);            }}void array_init(int number){    int i;    int value_temp;    for(i=0;i<number;i++)    {         cin >> value_temp;         array_my.push_back(value_temp);    }}void main(){    int i;    //array_init(3);    depart_init(3);        //it_department = department.begin();            for(it_department = department.begin();it_department != department.end();)//it_department++    {                for(i=0;i<LEN_JOB_NUMBER;i++)            cout << it_department->job_number[i];    //    cout << it_department->job_number;        cout << endl;        cout << it_department->salary<<endl;        //delete [] it_department->job_number;        department.erase(it_department);            }    //return 0;}