STL Pair

We use STL pair to store two values together.

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

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
pair<int, int> p;
pair<string, int> f;


This content originally appeared on DEV Community and was authored by Mujahida Joynab

We use STL pair to store two values together.

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    pair<int, int> p;
    pair<string, int> f;
    pair<char, double> g;
    // To make a vector pair
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    for(int i = 0 ; i < n ; i++){
        cin >> v[i].first >> v[i].second ;
    }
    for(int i = 0 ; i < n ; i++){
        cout << v[i].first << " " << v[i].second << endl ;
    }
    p = make_pair(2, 3);
    f = make_pair("Mujahida", 3);
    cout << f.first << endl;
    cout << f.second << endl;

    cout << p.first << endl;

    cout << p.second << endl;
}


This content originally appeared on DEV Community and was authored by Mujahida Joynab


Print Share Comment Cite Upload Translate Updates
APA

Mujahida Joynab | Sciencx (2025-02-13T21:40:35+00:00) STL Pair. Retrieved from https://www.scien.cx/2025/02/13/stl-pair/

MLA
" » STL Pair." Mujahida Joynab | Sciencx - Thursday February 13, 2025, https://www.scien.cx/2025/02/13/stl-pair/
HARVARD
Mujahida Joynab | Sciencx Thursday February 13, 2025 » STL Pair., viewed ,<https://www.scien.cx/2025/02/13/stl-pair/>
VANCOUVER
Mujahida Joynab | Sciencx - » STL Pair. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/02/13/stl-pair/
CHICAGO
" » STL Pair." Mujahida Joynab | Sciencx - Accessed . https://www.scien.cx/2025/02/13/stl-pair/
IEEE
" » STL Pair." Mujahida Joynab | Sciencx [Online]. Available: https://www.scien.cx/2025/02/13/stl-pair/. [Accessed: ]
rf:citation
» STL Pair | Mujahida Joynab | Sciencx | https://www.scien.cx/2025/02/13/stl-pair/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.