PAIR IN C++28 Aug 2024 | 4 min read Pair is a term used to combine two values, which may be of various data kinds. Pair offers a technique to keep two disparate objects together in storage. Essentially, we use it to store tuples. A pair container is a straightforward container that is specified in the header and contains two data elements or objects.
Syntax for pair in C++: Example: A program for pair in C++; Output 200 J Pair Initialization:A pair can also be initialized. You can use the following syntax to initialize pair. Syntax: Various approaches to pair initialization:The make pair() function can also be used to initialize a pair. Pair declaration may also use the following syntax: Example: Output JavaTpoint 2.23 Note: If the pair's first value is not initialized, it is initialized automatically.Example: Output 00 Member Functions1) make_pair(): Without explicitly defining the types, a value pair can be created using this template function. Syntax: Example: Output 200 J JavaTpoint 1.23 JavaTpoint is super 4.56 2) swap: The contents of two pair objects are switched with the use of this function. Pairs must belong to the same category. Syntax: Example: Output content before swapping: Contents of pair1 = P 1Contents of pair2 = Q 2 content after swapping: Contents of pair1 = Q 2Contents of pair2 = P 1 3) tie(): This tie() method works the same as tuples work. To unpack the tuple (or pair in this case) values into independent variables, it produces a tuple of lvalue pointers to its parameters. Here are two variations of the tie, one with and one without "ignore", just like in tuples. The keyword "ignore" prevents a certain tuple element from being unpacked. Pairs only have two arguments, but tuples can have numerous arguments. Therefore, unpacking needs to be dealt with explicitly in the case of pairs. Syntax: Example: Output 10 12 16 12 16 18 p |
C++ Books for Beginners
C++ is a similar kind of programming language which merges the features of the C programming language and Simula67 (it was recognized as the first object Oriented language). C++ set up the concept of Classes and Objects. Are you looking for a good book to start with...
6 min read
Babylonian Method to find Square Root in C++
You might need to quickly calculate square roots in your work as a software engineer or data scientist. The Babylonian algorithm is a well-liked approach to approximate square roots. In this post, we will examine the Babylonian algorithm for square roots in C++ and talk about...
3 min read
Block Swap Algorithm for Array Rotation in C++
In this article, you will learn about the block swap algorithm for array rotation in C++ with its example. But before going to its implementation, you must know about the array rotation. Rotations in C++:- A basic operation in programming and computer science is array rotation. It entails...
4 min read
Rint (), Rintf (), and Rintl () functions in C++
Rint(), Rintf(), and Rintl() functions in C++ In this article, you will learn about the rint(), rintf(), and rintl() functions in C++ with their syntax and examples. Introduction of "rint(), rintf(), rintl() function in C++": In C++, the rint(), rintf(), and rintl() capabilities are a part of the header...
4 min read
Adding Vectors in C++
Vectors in C++ are a dynamic array-based container that is used to store a collection of elements of the same type. Unlike arrays, vectors can grow or shrink in size dynamically, making it a convenient and efficient data structure for storing and manipulating data. A vector is...
4 min read
One time pad algorithm in C++
This C++ application uses the one-time pad cipher technique to encrypt any message. The input is case-insensitive and compatible with all characters. In the decrypted message, white spaces are generated as random characters rather than being disregarded. Example: The C++ program's source code for implementing the one-time pad...
3 min read
std::thread detach in C++
In today's software development landscape, multithreading is a fundamental concept that allows you to harness the full potential of modern, multi-core processors. For C++ developers, the Standard Library provides robust tools for managing threads, with std::thread being a central figure. One crucial aspect of working with...
6 min read
Rethrowing an Exception in C++
An Exception caught can be caught within a try block and handled using one or more Catch Blocks. A few cases exist where the exception is to be caught using a single Catch block and rethrow it, as the Catch block at the top of the...
4 min read
Thread Safe Queue in C++
In this article, we will discuss the thread safe queue in C++ with its example. What is Thread Safe Queue? A data structure called a thread-safe queue is made to ensure thread safety in concurrent environments. This data structure enables simultaneous enqueuing and dequeuing of elements by several...
4 min read
C++ program to find greatest of four numbers
In this tutorial, we will write a C++ program to find the greatest of four numbers. For example a = 10, b = 50, c = 20, d = 25 The greatest number is b 50 a = 35, b = 50, c = 99, d = 2 The greatest number...
4 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India