c_cpp Pairs_Syntax

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp Pairs_Syntax相关的知识,希望对你有一定的参考价值。

#include<bits/stdc++.h>
using namespace std;

// #CPP_STL #Pairs

int main(){
    // Pairs are C++ defined class
    // pair< data_type1, data_type 2> p
    // p.first gives first element in pair
    // p.second gives second element in pair
	pair<int,int> complex_num;
	complex_num.first=2;	// real part
	complex_num.second=3;	// imaginary part
	cout<<complex_num.first<<" + i"<<complex_num.second<<endl;

	// pair of different data types
	pair<int,bool> num_present;
	num_present.first=30;
	num_present.second=true;
	cout<<num_present.first<<" is ";
	if(num_present.second==true){
		cout<<"present";
	}
	cout<<endl;
	
	// defining a pair
	pair<int,int> co_ord = {2,3};
	cout<<"X co-ord is "<< cod_ord.first<<endl;
	cout<<"Y co-ord is "<< cod_ord.second<<endl;
	
	return 0;
}

以上是关于c_cpp Pairs_Syntax的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 200.岛屿数量

c_cpp 127.单词阶梯

c_cpp MOFSET

c_cpp MOFSET

c_cpp 31.下一个排列

c_cpp string→char *