Most voted questions in C++

0 votes
1 answer

Check if element is in the list (contains)

The simplest and quickest method. You could also ...READ MORE

Jun 2, 2022 in C++ by Damon
• 4,960 points
2,066 views
0 votes
0 answers

Code Not working in VS Code but works in OnlineGDB

I am practicing about primeSieve with C++ language in VS Code 1.57.1. Can ...READ MORE

Jun 1, 2022 in C++ by Nicholas
• 7,760 points
713 views
0 votes
0 answers

How to implement 2D vector array?

I'm using the vector class in the ...READ MORE

Jun 1, 2022 in C++ by Nicholas
• 7,760 points
389 views
0 votes
0 answers

How to implement 2D vector array?

I'm using the vector class in the ...READ MORE

Jun 1, 2022 in C++ by Nicholas
• 7,760 points
525 views
0 votes
0 answers

What is the C++ function to raise a number to a power?

What's the best way to raise a n ...READ MORE

Jun 1, 2022 in C++ by Nicholas
• 7,760 points
506 views
0 votes
0 answers

How to traverse stack in C++?

Is traversing std::stack possible in C++? It is not possible to traverse using the following method.  Because there is no member end in std::stack. std::stack<int> foo; // .. for (__typeof(foo.begin()) it = foo.begin(); ...READ MORE

Jun 1, 2022 in C++ by Nicholas
• 7,760 points
2,151 views
0 votes
1 answer

Using getline() in C++

If you use getline() after cin >> anything, you must first flush the newline character from the buffer.  You can achieve this by using the cin.ignore() It would be something like this: string messageVar; cout ...READ MORE

Jun 1, 2022 in C++ by Damon
• 4,960 points
879 views
0 votes
1 answer

How to use std::sort to sort an array in C++

We receive std::begin and std::end in C++0x/11, which are overloaded for arrays: #include <algorithm> int main(){ int v[2000]; ...READ MORE

Jun 1, 2022 in C++ by Damon
• 4,960 points
1,127 views
0 votes
1 answer

Why does C++ need the scope resolution operator?

No. There is no scope resolution operator ...READ MORE

Jun 1, 2022 in C++ by Damon
• 4,960 points
858 views
0 votes
1 answer

Why is "using namespace std;" considered bad practice?

This has nothing to do with performan ...READ MORE

Jun 1, 2022 in C++ by Damon
• 4,960 points
864 views
0 votes
1 answer

How to reverse an std::string?

A reverse function is integrated into C++ and can be used to reverse a string.  This function accepts two parameters: The start iterator for the string The string iterator has come to an end. The following line of code demonstrates how to use this function: #include <iostream> //The library below must be included ...READ MORE

Jun 1, 2022 in C++ by Damon
• 4,960 points
530 views
0 votes
1 answer

The Definitive C++ Book Guide and List

For Beginner (includes those without coding experience) Programming: ...READ MORE

Jun 6, 2022 in C++ by pranav
• 2,590 points
891 views
0 votes
0 answers

Intersection of two std::unordered_map

I have two std::unordered_map std::unordered_map<int, int> mp1; std::unordered_map<int, int> ...READ MORE

May 31, 2022 in C++ by Nicholas
• 7,760 points
759 views
0 votes
1 answer

Sorting a vector of custom objects

A simple example using std::sort struct MyStruct { ...READ MORE

Jun 1, 2022 in C++ by Damon
• 4,960 points
1,252 views
0 votes
1 answer

How can I convert a std::string to int?

There are some new convert methods in C++ that convert std::string to a numeric type. As an alternative to str.c str() atoi(str.c str()) atoi(str.c str() you can make use of std::stoi std::stoi ...READ MORE

Jun 1, 2022 in C++ by Damon
• 4,960 points
684 views
0 votes
1 answer

Why would anyone use set instead of unordered_set?

Unordered sets must compensate for their O(1) ...READ MORE

Jun 1, 2022 in C++ by Damon
• 4,960 points
2,903 views
0 votes
1 answer

Easiest way to convert int to string in C++

C++ adds std::stoi (and variants for each numeric type) and std::to string, which are the C equivalents of atoi and itoa but expressed in terms of std::string #include <string> std::string s = std::to_string(42); Is therefore ...READ MORE

Jun 1, 2022 in C++ by Damon
• 4,960 points
1,371 views
0 votes
1 answer

C++ `this` pointer

Pointer variables are used to store the ...READ MORE

May 31, 2022 in C++ by Damon
• 4,960 points
570 views
0 votes
1 answer

What data structure is inside std::map in C++?

An associative container is std::map. The standard's ...READ MORE

May 31, 2022 in C++ by Damon
• 4,960 points
831 views
0 votes
1 answer

Syntax of priority queue

We must first include the queue header file in order to establish a priority queue in C++. #include <queue> Once we import this file, we ...READ MORE

May 31, 2022 in C++ by Damon
• 4,960 points
587 views
0 votes
1 answer

Declare abstract class in c++

An abstract class is one that is intended to be used as a base class .  At least one pure virtual function exists in an abstract class.  A pure virtual function is declared in the class declaration by using a pure specifier (= 0) in the declaration of a virtual member function. Here is an example of an abstract class: class AB { public: virtual void f() ...READ MORE

May 31, 2022 in C++ by Damon
• 4,960 points
556 views
0 votes
1 answer

why are copy constructors needed and what are the cases where they are very helpful?

A copy constructor is a member function ...READ MORE

May 31, 2022 in C++ by Damon
• 4,960 points
803 views