̸̸C++ѧϰ֮Pairʹ÷

 ʱ䣺20161221 11:10:07   ߣOceanLight  
pairһģͣаֵݵͿԲͬ,ƪϸĽPairʹ÷ʵȤͬѧ˽һ¡

һPair͸

pairһģͣаֵݵͿԲͬĶ£

pair<int, string> a;

ʾaͣһԪint͵ģڶԪstring͵ģpairʱûжгʼĬϹ캯ʼ

pair<string, string> a("James", "Joy");

ҲһڶʱֱӶʼ

pair͵ʹñȽϷΪҪͬpair͵ʱ򣬿ʱtypedef

typedef pair<string, string> author;
author pro("May", "Lily");
author joye("James", "Joyce");

PairIJ

1pairֻ࣬ԪأֱΪfirstsecondֱʹͨĵɷԱ

pair<string, string> a("Lily", "Poly"); 
string name;
name = pair.second;

2µpair

ʹmake_pairѴڵݹһµpairͣ

int a = 8;
string m = "James";
pair<int, string> newone;
newone = make_pair(a, m);

ʵ

ϰдһϵstringintݣÿһ洢һpairУȻЩpair洢vector

#include<iostream>
#include<string>
#include<vector>
#include<utility>
using namespace std;

int main()
{
  pair<string, int>p;
  typedef vector< pair<string, int> > VP;
  VP vp;
  while(cin>>p.first>>p.second)
  {
    vp.push_back(make_pair(p.first,p.second));
    
  }
  VP::iterator it;
  for(it=vp.begin(); it!=vp.end(); it++)
    cout<<it->first<<","<<it->second<<endl;

  return 0;
}

ϾDZĵȫݣϣԴҵѧϰҲϣҶֽ֧ű֮ҡ

  • C++  Unreal ΪϷʵʱƵĽ̳

    C++ Unreal ΪϷʵʱƵĽ̳

    ƪҪC++ Unreal ΪϷʵʱƵĽ̳̣ͨͼIJïʽҽܵķdzϸԴҵѧϰһIJοֵ,ҪѿԲο
    2020-05-05
  • C++ʵСϷ

    C++ʵСϷ

    Ľ˼Ϸ뿪̳ƱȽ,Ƹʵֶʵ,չԺͿάԡյijԴ룬ƼңҪСԲο¡
    2015-03-03
  • C &  &&

    C & &&

    ƪҪC & &&⣬ͨʾܵķdzϸԴҵѧϰ߹һIJοѧϰֵҪСһѧϰѧϰ
    2021-01-01
  • TC2.0еû

    TC2.0еû

    ƪ½ˣTC2.0еûĽҪѲο
    2013-05-05
  • VCSDKMFCdz

    VCSDKMFCdz

    ƪҪVCSDKMFCdz,ҪѿԲο
    2014-07-07
  • C++ const麯ʵ

    C++ const麯ʵ

    ƪҪC++ const麯ʵ,ҪѿԲο
    2017-06-06
  • 򵥽Cеumask()truncate()

    򵥽Cеumask()truncate()

    ƪҪ˼򵥽Cеumask()truncate(),CѧϰеĻ֪ʶ,ҪѿԲο
    2015-09-09
  • Cλsizeof

    Cλsizeof

    ƪҪCλsizeof,ṩϸ֪ʶҪ㣬򵥴ʾҪѿԲο
    2016-11-11
  • C++

    C++

    ǶC++еĿϸĽܣҪѿԹο
    2013-09-09
  • ĵݹʵǵݹʵ

    ĵݹʵǵݹʵ

    ǶĵݹʵǵݹʵֽϸķܣҪѿԹο
    2013-07-07