Trending questions in C++

0 votes
0 answers

const int *p vs. int const *p - Is const after the type acceptable?

My coworker is 0 for 2 on questions inspired by him (1, 2), so I decided to give him a chance to catch up. Our most recent argument is about the placement of "const" on declarations. He believes it should be placed either in front of the type or after the pointer.  The explanation is that this is what everyone else does, and different styles are likely to be confusing.  Thus, a constant pointer to int and a constant pointer to int would be: const int *i; ...READ MORE

Jul 22, 2022 in C++ by Nicholas
• 7,760 points
552 views
0 votes
0 answers

Default inheritance access specifier

If I have two classes A and ...READ MORE

Jul 22, 2022 in C++ by Nicholas
• 7,760 points
476 views
0 votes
1 answer

Sorting vector elements in descending order

Because of the goto reset instruction, I believe your sort function has entered an infinite loop.  If you wish to construct a basic bubble-sort algorithm, follow these steps: #include <iostream> #include <utility> #include <vector> void bubble_sort(std::vector<int>& v) { ...READ MORE

Jul 11, 2022 in C++ by Damon
• 4,960 points
985 views
+1 vote
0 answers

Using push_back vs at in a vector in C++

I'm not sure how to use vectors in C++.  It has to do with the vector's push back technique.  I used push back to insert entries into the vector in the first programme.  I used at() to insert entries into the vector in the second application. #include <iostream> #include <vector> #include <string> using namespace std; int main ...READ MORE

Jul 22, 2022 in C++ by Nicholas
• 7,760 points
405 views
0 votes
0 answers

How to find if a given key exists in a C++ std::map

I'm trying to check if a given ...READ MORE

Jul 14, 2022 in C++ by Nicholas
• 7,760 points
771 views
0 votes
0 answers

Converting Binary to Decimal built-in function

In C++, I need to do a ...READ MORE

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

Successor of INT_MAX and INT_MIN

I have two inquiries. Is 1e9 smaller than ...READ MORE

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

Difference between upper_bound and lower_bound in stl

I was looking at how the upper bound and lower bound algorithms operate in stl on these pages: lower bound, upper bound, and it's documented the same way on these pages: lower bound, upper bound, and it's documented the same way on these pages: lower bound, upper bound, and it'  upper bound, lower bound Looking at the code from the links, they appear to perform the same thing to me, with the exception of the following lines  lower_bound (line 10): if (*it<val) { ...READ MORE

Jul 5, 2022 in C++ by Nicholas
• 7,760 points
1,122 views
0 votes
0 answers

What is the fastest way to transpose a matrix in C++?

I have a reasonably large matrix that I need to transpose.  Assume, for example, that my matrix is a b c d e f g h ...READ MORE

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

What are access specifiers? Should I inherit with private, protected or public?

I'm not sure what access modifiers signify ...READ MORE

Jul 22, 2022 in C++ by Nicholas
• 7,760 points
364 views
0 votes
0 answers

What is the difference between Java and C++?

What is the difference between Java and ...READ MORE

Jul 22, 2022 in C++ by Nicholas
• 7,760 points
362 views
0 votes
0 answers

Visual C++ vs Visual C# , which is the best to learn?

I completed my C++ lessons and practises ...READ MORE

Jul 22, 2022 in C++ by Nicholas
• 7,760 points
352 views
0 votes
0 answers

Using "super" in C++

The following phrase is part of my coding approach: class Derived : public Base { ...READ MORE

Jul 13, 2022 in C++ by Nicholas
• 7,760 points
739 views
0 votes
1 answer

How can I get all the unique keys in a multimap

This method worked for me. for( multimap<char,int>::iterator it ...READ MORE

Jun 27, 2022 in C++ by Damon
• 4,960 points
1,498 views
0 votes
0 answers

XOR Operation Intuition

Except for one, every element in an array of numbers appears twice.  Locate that solitary one. Keep in mind that your algorithm should have a linear runtime complexity.  Could you do that without using any more memory? class Solution { public: int ...READ MORE

Jul 22, 2022 in C++ by Nicholas
• 7,760 points
342 views
0 votes
0 answers

What is the difference between ifstream, ofstream and fstream?

I stumbled discovered ifstream, ofstream, and fstream ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
790 views
0 votes
0 answers

How member functions are implemented in C++?

I read somewhere that member functions in C++ are similar to regular functions but with an additional implicit this parameter. As a result, I assumed that this software would be unable to discriminate between two functions.  However, the software executed successfully.  So, was the above statement incorrect? #include <iostream> class MyCls { ...READ MORE

Jul 22, 2022 in C++ by Nicholas
• 7,760 points
304 views
0 votes
1 answer

What is the difference between public, private, and protected inheritance in C++?

To begin answering that question, let me characterise member accessors in my own terms.  If you already know this, proceed to the section "next:". I'm aware of three types of accessors: public, protected, and private. Let: class Base { public: ...READ MORE

Jul 11, 2022 in C++ by Damon
• 4,960 points
750 views
0 votes
1 answer

c++ constructor and copy constructor

In a pre-C++17 compiler, this is known as copy elision (test it with C++17 on compiler explorer or wandbox with -std=c++17 vs. -std=c++14 flags).  As of C++17, the compiler must delete numerous instances of copy and move constructors and create objects directly without the need of intermediary objects. Unlike A a { 10 }; the line A a ...READ MORE

Jun 27, 2022 in C++ by Damon
• 4,960 points
1,381 views
0 votes
0 answers

Simple example of threading in C++

Could someone maybe provide a basic C++ ...READ MORE

Jul 15, 2022 in C++ by Nicholas
• 7,760 points
533 views
0 votes
1 answer

How do i apply lower_bound to a range of unsorted vector elements?

What's the point of sorting your array? ...READ MORE

Jun 15, 2022 in C++ by Damon
• 4,960 points
1,770 views
0 votes
0 answers

How to convert a char array to a string?

Converting a C++ string to a char ...READ MORE

Jul 14, 2022 in C++ by Nicholas
• 7,760 points
524 views
0 votes
1 answer

C++ code file extension? What is the difference between .cc and .cpp [closed]

GNU GCC recognizes all of the following ...READ MORE

Jun 21, 2022 in C++ by Damon
• 4,960 points
1,512 views
0 votes
0 answers

How do I declare a 2d array in C++ using new?

How do I declare a two-dimensional array using new? For example, for a "typical" array, I would:      int* ary = new int[Size] but int** ...READ MORE

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

dynamic_cast and static_cast in C++

 I'm perplexed by the dynamic cast keyword in C++. struct A { virtual ...READ MORE

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

What is the meaning of "generic programming" in c++?

What does generic programming in C++ mean? I'm ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
630 views
0 votes
0 answers

What is object slicing?

What is object slicing in C++ and ...READ MORE

Jul 13, 2022 in C++ by Nicholas
• 7,760 points
556 views
0 votes
0 answers

how the iterator in c++ could be printed?

Suppose, I have declared a vector in C++ like ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
619 views
0 votes
1 answer

Why is Turbo C++ showing this error in DOSBox on my Mac?

Your installation must be defective!  I have a Mac, and I'm typing this on it while using TurboC++.  Consider uninstalling and then reinstalling the programme. Download the package in the same way as you would a.dmg programme from the internet.  (For example, drag and drop the programme into the Applications folder)  Ascertain that your Applications folder is global to your system.  This is what I mean: When in Finder, select the "GO" option from the top menu bar. From the drop down option, choose "Computer." In the newly opened window, click on your hard disc. There is a "Applications" folder there.  That's where you should put TurboC++. Go to Launchpad, and start Turbo C++. ...READ MORE

Jun 28, 2022 in C++ by Damon
• 4,960 points
1,143 views
0 votes
0 answers

C++ vector erase function not working properly

Here is the code I want to use to delete any entries with values more than 2 and fewer than 5. vector<int> myvector{3, 3, 3, 3, 3, 3, ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
611 views
0 votes
0 answers

Difference between for loop and the range based loop in C++

The distinction between a for loop and ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
596 views
0 votes
0 answers

How does c++ std::vector work?

How do the addition and removal of ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
593 views
0 votes
0 answers

not able to run graphics in DEV C++

Unable to run the graphics from following ...READ MORE

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

C++ convert from 1 char to string?

I simply need to cast one character to string.  The inverse method is as easy as str[0]. The following suggestions did not work for me: char c = 34; string(1,c); //this doesn't work, the ...READ MORE

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

How to create a dynamic array of integers

How can I use the new keyword ...READ MORE

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

Check if a string is palindrome

I need to write a software that ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
510 views
+1 vote
0 answers

Parse (split) a string in C++ using string delimiter (standard C++)

In C++, I'm processing a string like follows: using namespace std; string parsed,input="text to be parsed"; stringstream ...READ MORE

Jul 4, 2022 in C++ by Nicholas
• 7,760 points
778 views
0 votes
0 answers

Program to calculate square root c++

Making a C++ application to determine a number's square root.  The built-in arithmetic operator "sqrt" is not used in this application.  There are two variables: one for the user-inputted integer and the other for the number's square root.  This software does not function very well, and I am certain that there is a more effective method to accomplish it: Here is my full code: #include <iostream> using namespace ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
503 views
0 votes
0 answers

Why aren't cmath's pow and sqrt templates?

I'm curious as to why std::sqrt and ...READ MORE

Jul 13, 2022 in C++ by Nicholas
• 7,760 points
428 views
0 votes
0 answers

How to use setprecision in C++

I'm new to C++ and all I want to do is print my point number up to two digits.  For example, if the number is 3.444, the output should be 3.44, and if the number is 99999.4234, the output should be 99999.42.  How am I going to do that?  The value changes over time.  This is my code. #include <iomanip.h> #include <iomanip> int main() { ...READ MORE

Jul 5, 2022 in C++ by Nicholas
• 7,760 points
765 views
0 votes
1 answer

C++ string input

To read from cin, use a std::string.  Then you don't have to guess how big your buffer should be. std::string input; cin >> input; cout << intput; If you ...READ MORE

Jul 11, 2022 in C++ by Damon
• 4,960 points
505 views
0 votes
1 answer

What is the difference between std::__gcd and std::gcd?

I done some research about this. The ...READ MORE

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

Is there an easy way to make a min heap in C++?

Use make heap() and its buddies from algorithm>, or priority queue from queue>.  Make heap and friends are used by priority queue. #include <queue> // functional,iostream,ctime,cstdlib using namespace std; int main(int ...READ MORE

Jun 27, 2022 in C++ by Damon
• 4,960 points
1,024 views
0 votes
0 answers

When and why do I need to use cin.ignore() in C++?

In C++, I developed a simple application that requested the user to enter a number and then a string.  Surprisingly, when I ran the application, it never paused to ask for the string.  It simply ignored it.  After conducting some research on StackOverflow, I discovered that I needed to include the following line: cin.ignore(256, '\n'); before the line with the string input  That addressed the problem and allowed the software to run.  My issue is why C++ need the cin.ignore() line, and how can I forecast when I will need to use it. Here's the software I created: #include <iostream> #include <string> using namespace std; int main() { ...READ MORE

Jul 4, 2022 in C++ by Nicholas
• 7,760 points
759 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,181 views
0 votes
0 answers

Purpose of Unions in C and C++

I had previously utilised unions with ease; however, I was startled when I read this post and discovered that this code union ARGB { uint32_t colour; ...READ MORE

Jul 13, 2022 in C++ by Nicholas
• 7,760 points
351 views
0 votes
0 answers

What are the differences between a pointer variable and a reference variable?

What distinguishes a reference variable from a ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
430 views
0 votes
0 answers

throwing a run time error

I just started Programming: Principles and Practice Using C++ because I'm new to programming.  Errors and how to handle them are covered in one of the chapters. What I'm attempting to implement is this little line of code.  The programme will end with a system error message and the text we gave as a parameter, according to the book's description of error(). #include <iostream> #include <string> using namespace std; int area (int ...READ MORE

Jul 13, 2022 in C++ by Nicholas
• 7,760 points
356 views
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,081 views
0 votes
0 answers

Do you use Qt and why do you use it?

Cons and advantages? How long does it ...READ MORE

Jul 13, 2022 in C++ by Nicholas
• 7,760 points
350 views