vector——ing

来源:互联网 发布:英轩重工怎么样知乎 编辑:程序博客网 时间:2024/05/08 08:40

//h.h

#pragma  once
#include <iostream>
#include <vector>
#include <string>
#include <conio.h>
#include <atlstr.h>//CString

using namespace std;

typedef struct {
 int i;
 string str;
 CString Cstr;
}node;
template <typename T>
void PushMyVector(vector<T> &str)
{
 T word;
 cout<<"now man input"<<endl;
 cin>>word;
 cout<<endl;
 str.push_back(word);

 //word = "auto input value";
 //cout<<"now auto input:"<<word<<endl;
 //str.push_back(word);
 //T word2= "auto input2";
 //str.push_back(word2);
}
template <typename T>
void PrintMyVector(vector<T> &str)
{
 vector<T>::iterator it_vs;
 cout<<"now print"<<endl;
 for (it_vs= str.begin() ;it_vs != str.end(); it_vs++)
 {
  cout<<*it_vs<<endl;
 }
}

//void PushMyVector(vector<int> &myInt)
//{
// int word;
// cout<<"now man input"<<endl;
// cin>>word;
// cout<<endl;
// myInt.push_back(word);
// word = 16890;
// cout<<"now auto input:"<<word<<endl;
// myInt.push_back(word);
// int word2= 123456;
// myInt.push_back(word2);
//}
//void PrintMyVector(vector<int> &myInt)
//{
// vector<int>::iterator it_vs;
// cout<<"now print"<<endl;
// for (it_vs= myInt.begin() ;it_vs != myInt.end(); it_vs++)
// {
//  cout<<*it_vs<<endl;
// }
//}

 

void PushMyVector(vector<node> &myInt)
{
 CString Str="CString";
 node word;
 cout<<"now man input"<<endl;
 cin>>word.i;
 cin>>word.str;
 cin>>word.Cstr.GetBuffer();
 cout<<endl;
 myInt.push_back(word);

 word.i=234;
 word.str =Str.GetBuffer();
 word.Cstr="cstringdf no new";
 cout<<"now auto input:"<<word.i<<"  "<<word.str<<"  "<<word.Cstr<<endl;
 myInt.push_back(word);

 node word2={1234334,"asasdf","cstringdf"};
 myInt.push_back(word2);
}
void PrintMyVector(vector<node>& myInt)
{
 vector<node>::iterator it_vs;
 cout<<"now print"<<endl;
 for (it_vs= myInt.begin() ;it_vs != myInt.end(); it_vs++)
 {
  cout<<(*it_vs).i<<"  "<<(*it_vs).str<<"  "<<(*it_vs).Cstr.GetBuffer()<<endl;
 }

//t1.cpp

#include <iostream>
#include <vector>
#include <string>
#include <conio.h>
#include <atlstr.h>//CString
#include "h.h"

using namespace std;

 

void main()
{
 vector<string> myStr;
 PushMyVector(myStr); 
 PrintMyVector(myStr);


 vector<int> myInt;
 PushMyVector(myInt);
 PrintMyVector(myInt);

 vector<node> myStruct;
 PushMyVector(myStruct);
 PrintMyVector(myStruct);

 getch();


}

 

原创粉丝点击