Found 7401 Articles for C++

multiset insert() function in C++ STL

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

140 Views

The multiset insert() function in C++ STL which insert elements in the multiset container from a position to another position from one multiset to a different multiset.List of functions used:ms.size() = Returns the size of multiset. ms.insert() = It is used to insert elements to the multiset.Example Code#include #include #include #include using namespace std; int main() {    multiset ms;    multiset::iterator it, it1;    int c, i;    while (1) {       cout

lldiv() function in C++ STL

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

81 Views

lldiv() function in C++ STL gives the result of quotient and remainder of the division of the two numbers.AlgorithmBegin Take two long type numbers as input. Call function lldiv(). Print the quotient and remainder. End.Example Code#include #include using namespace std; int main() {    long long q = 500LL;    long long r = 25LL;    lldiv_t res = lldiv(q, r);    cout

iswalpha() function in C++ STL

Nitya Raut
Updated on 30-Jul-2019 22:30:25

80 Views

iswalpha() function in C++ STL is used to check whether the given wide character is an alphabet or not.AlgorithmBegin Initializes the strings. Call function iswalpha(str) to check whether it contains alphabet or not. If it contains alphabet, then value will be returned otherwise zero will be returned. EndExample Code#include #include #include #include using namespace std; int main() {    setlocale(LC_ALL, "ab1234");    wchar_t s[] = L"a%$^^&)";    bool flag = 0;    for (int i=0; i

iswalnum() function in C++ STL

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

121 Views

iswalnum() function in C++ STL checks if the given wide character is an alphanumeric character, i.e. either a number (0-9), an uppercase letter(A-Z), a lowercase letter (a-z) or any alphanumeric character or not.AlgorithmBegin Initializes the characters. Call function iswalnum(c1) to check whether it is alphanumeric or not. If it is alphanumeric character, then value will be returned otherwise zero will be returned. EndExample Code#include #include using namespace std; int main() {    wchar_t c1 = '/';    wchar_t c2 = 'a';    if (iswalnum(c1))       wcout

Insertion and Deletion in STL Set C++

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

653 Views

InsertionInsertion in STL set can be done by insert() and emplace() operation.Insert(): Insert() is used to insert elements to the set. Insert operation takes a reference to an object.List of functions are used:st.size() = Returns the size of set. st.insert() = It is used to insert elements to the set.Example Code#include #include #include #include using namespace std; int main() {    set st;    set::iterator it;    int c, i;    while (1) {       cout

How to remove an item from a C++ STL vector with a certain value?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

564 Views

Erase function is used to remove an item from a C++ STL vector with a certain value.AlgorithmBegin Declare vector v and iterator it to the vector. Initialize the vector. Erase() function is used to remove item from end. Print the remaining elements. End.Example Code#include #include using namespace std; int main() {    vector v{ 6,7,8,9,10};    vector::iterator it;    it = v.end();    it--;    v.erase(it);    for (auto it = v.begin(); it != v.end(); ++it)       cout

emplace vs insert in C++ STL

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

925 Views

emplace operation avoids unnecessary copy of object and does the insertion more efficiently than insert operation. Insert operation takes a reference to an object.AlgorithmBegin Declare set. Use emplace() to insert pair. Use insert() to insert pair by using emplace(). Print the set. EndExample Code#include using namespace std; int main() {    set s;    s.emplace(7, 'a');    s.insert(make_pair(6, 'b'));    for (auto it = s.begin(); it != s.end(); ++it)       cout

Descending order in Map and Multimap of C++ STL

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

3K+ Views

Generally, the default behavior of map and multimap map is to store elements is in ascending order. But we can store element in descending order by using the greater function.The map in descending order:Functions are used here -m::find() – Returns an iterator to the element with key value ‘b’ in the map if found, else returns the iterator to end.m::erase() – Removes the key value from the map.m:: equal_range() – Returns an iterator of pairs. The pair refers to the bounds of a range that includes all the elements in the container which have a key equivalent to key.m insert() ... Read More

C++ Program to Implement Vector in STL

Nitya Raut
Updated on 30-Jul-2019 22:30:25

381 Views

Vectors have the ability to resize itself automatically like dynamic arrays when an element is inserted or deleted, the container handle their storage automatically. Vector elements are placed in contiguous storage so that they can be accessed and traversed using iterators. Data can be inserted or erased at the begin, middle or end of the vector.Functions and descriptions:List of functions used here:    v.size() = Returns the size of vector.    v.push_back() = It is used to insert elements to the vector from end.    v.pop_back() = To pop out the value from the vector from back.    v.capacity() = ... Read More

C++ Program to Implement Stack in STL

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

798 Views

Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be FILO (First In first out) or LIFO (Last In First Out)AlgorithmBegin Declare stack vector. Take the input as per choice. Call the functions within switch operation: s.size() = Returns the size of stack. s.push() = It is used to insert elements to the stack. s.pop() = To pop out the value from the stack. s.top() = Returns a ... Read More

Advertisements