Most answered questions in C++

0 votes
0 answers

Selection sort in C++ (modified) not working for all cases

I was attempting to tweak the selection sort code in C++ in order to test the results.  My updated code is as follows: #include<bits/stdc++.h> using namespace std; int main() { ...READ MORE

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

What is the STL?

I'm not a C++ coder, thus I ...READ MORE

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

Difference between set.upper_bound() and upper_bound(set.begin(), set.end()) stl

I discovered that set.upper bound() was quicker ...READ MORE

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

Why are exceptions so rarely used in C++

I've been writing in C++ on and ...READ MORE

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

Sorting Characters Of A C++ String

Is there a built-in method for sorting characters in a string, or do I have to construct my own? for instance: string word = "dabc"; I would want to ...READ MORE

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

How to use the priority queue STL for objects?

class Person { public: int age; }; I'd want to put objects of the type Person in a priority queue. priority_queue< ...READ MORE

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

Can you use "cin" with string?

To enter a string, I was instructed to use gets(str) rather than cin.  In the programme below, though, I can use cin perfectly well.  Could you please tell me if you can use cin?  Please accept my apologies for my poor English.  The application allows you to enter up to five names and then print them on the screen. The code is as follows: #include <iostream> #include <string.h> using namespace std; int main() { ...READ MORE

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

C++ pointer to objects

Is it always necessary in C++ to  ...READ MORE

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

How can I get the maximum or minimum value in a vector?

In C++, how can I find the greatest or minimum value in a vector? Is it correct to assume that it would be similar with an array? Do I require an iterator?  I tried max element, but I kept receiving errors. vector<int>::const_iterator it; it = max_element(cloud.begin(), cloud.end()); error: request for ...READ MORE

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

What is the easiest way to initialize a std::vector with hardcoded elements?

I can make an array and initialise&nb ...READ MORE

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

Difference between 'new operator' and 'operator new'?

What is difference between "new operator" and ...READ MORE

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

static memory allocation like dynamic memory allocation

int r, c; cin >> r >> c; int ...READ MORE

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

functions in c++ call by value and call by reference

The code below shows how to call a function in both methods.  Please explain the major differences or meanings of call by value and call by reference to me.  1.Make a value-based call.  2.Call based on a reference.  The call by value method is demonstrated in the following code. In a comment, I expressed my reservations. #include<iostream> int main(){ void change(int);//why function prototype is before ...READ MORE

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

Use of min and max functions in C++

Are std::min and std::max better than fmin ...READ MORE

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

Constructor Overloading in C++

My C++ overloading does not work as I expect it to: #include "Node.h" #include <iostream> Node::Node() { cout ...READ MORE

Jun 2, 2022 in C++ by Nicholas
• 7,760 points
241 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
558 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
259 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
349 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
313 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
1,640 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
503 views