C++ Articles - Page 414 of 719

multiset lower_bound() in C++ STL with Examples

Ayush Gupta
Updated on 06-Apr-2020 14:05:36

366 Views

In this tutorial, we will be discussing a program to understand multiset lower_bound() in C++ STL.The function lower_bound() returns the first existence of the element in the container equivalent to the provided parameter, else it returns the element immediately bigger than that.Example Live Demo#include using namespace std; int main(){    multiset s;    s.insert(1);    s.insert(2);    s.insert(2);    s.insert(1);    s.insert(4);    cout

multiset upper_bound() in C++ STL with Examples

Ayush Gupta
Updated on 06-Apr-2020 14:00:38

364 Views

In this tutorial, we will be discussing a program to understand multiset upper_bound() in C++ STL.The function upper_bound() returns the pointer to an element which is bigger than the one provided as a parameter, else it returns the pointer to the last element in the container.Example Live Demo#include using namespace std; int main(){    multiset s;    s.insert(1);    s.insert(3);    s.insert(3);    s.insert(5);    s.insert(4);    cout

negative_binomial_distribution in C++ with Examples

Ayush Gupta
Updated on 06-Apr-2020 13:58:33

196 Views

In this tutorial, we will be discussing a program to understand negative_binomial_distribution in C++.This function follows the negative Binomial discrete distribution and produces integers according to this random distribution.Example Live Demo#include using namespace std; int main() {    //setting number of experiments    const int exps = 10000;    const int numberstars = 100;    default_random_engine generator;    negative_binomial_distribution distribution(4, 0.5);    int p[10] = {};    for (int i = 0; i < exps; ++i) {       int counting = distribution(generator);       if (counting < 10)          ++p[counting];    }    cout

multiset max_size() in C++ STL with Examples

Ayush Gupta
Updated on 06-Apr-2020 13:55:35

153 Views

In this tutorial, we will be discussing a program to understand multiset max_size() in C++ STL.The function max_size() returns the maximum number of elements a given container can hold.Example Live Demo#include using namespace std; int main(){    multiset s;    s.insert(10);    s.insert(13);    s.insert(13);    s.insert(25);    s.insert(24);    cout

multiset size() in C++ STL with Examples

Ayush Gupta
Updated on 06-Apr-2020 13:53:28

137 Views

In this tutorial, we will be discussing a program to understand multiset size() in C++ STL.The function size() returns the number of elements present into a given container.Example Live Demo#include using namespace std; int main(){    multiset s;    s.insert(10);    s.insert(13);    cout

order_of_key() in C++

Ayush Gupta
Updated on 06-Apr-2020 13:51:29

845 Views

In this tutorial, we will be discussing a program to understand order_of_key() in C++.The function order_of_key() takes in a key and returns the number of elements which are less than the key provided as parameter in an ordered set.Example Live Demo#include using namespace std; #include #include #include #include using namespace __gnu_pbds; using namespace std; //initializing ordered set typedef tree    ordered_set; int main(){    ordered_set mySet;    mySet.insert(5);    mySet.insert(2);    mySet.insert(6);    mySet.insert(4);       cout

MakeFile in C++ and its applications

Ayush Gupta
Updated on 01-Apr-2020 06:46:17

270 Views

In this tutorial, we will be discussing a program to understand MakeFile in C++ and its applications.The task is to break the entire program with MakeFile. It is usually done by making .cpp files and .h files with all the classes/functionalities and link them together.Examplemain.cpp#include #include "function.h" using namespace std; //main execution program int main(){    int num1 = 1;    int num2 = 2;    cout

Kruskal’s Minimum Spanning Tree using STL in C++

Ayush Gupta
Updated on 01-Apr-2020 06:43:15

513 Views

In this tutorial, we will be discussing a program to understand Kruskal’s minimum spanning tree using STL in C++.For this, we will be provided with a connected, undirected and weighted graph. Our task is to calculate the Minimum spanning tree for the given graph.Example Live Demo#include using namespace std; typedef pair iPair; //structure for graph struct Graph{    int V, E;    vector< pair > edges;    Graph(int V, int E){       this->V = V;       this->E = E;    }    void addEdge(int u, int v, int w){       edges.push_back({w, {u, v}});    } ... Read More

Lower bound in C++

Ayush Gupta
Updated on 01-Apr-2020 06:41:03

327 Views

In this tutorial, we will be discussing a program to understand the lower bound in C++.lower_bound() method in C++ is used to return the very first number in the container object which is not less than the given value.Example Live Demo#include int main(){    std::vector v{ 10, 20, 30, 40, 50 };    std::cout

Iseek() in C/C++ to read the alternate nth byte and write it in another file

Ayush Gupta
Updated on 01-Apr-2020 06:38:41

749 Views

In this tutorial, we will be discussing a program to understand how to read the alternate nth byte and write it in another file.For this, we will be provided with two .txt files. Our task is to write the contents from one file to another file using Iseek() which is used to change the pointer of the file descriptor.Example#include #include #include #include void func(char arr[], int n){    int f_write = open("start.txt", O_RDONLY);    int f_read = open("end.txt", O_WRONLY);    int count = 0;    while (read(f_write, arr, 1)){       if (count < n) ... Read More

Advertisements