Most answered questions in C++

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
228 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
231 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
590 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
336 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
200 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
462 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
394 views
0 votes
0 answers

How can I terminate an infinite loop in Turbo C?

I get caught in an infinite loop.  How can I break this cycle?  Cntrl-C was attempted, however it had little effect.  I have no idea how to stop it. main() { ...READ MORE

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

Finding square root without using sqrt function?

I tried to incorporate the technique I had discovered for calculating the square root without utilising the sqrt function into programming.  I finally have this C++ code that runs. #include <iostream> using ...READ MORE

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

What's the Use of '\r' escape sequence?

I have C code like this: #include<stdio.h> int main() { ...READ MORE

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

Purpose of Unions in C and C++

I had previously used unions with ease, but when I read this post and learned that this code union ARGB { uint32_t colour; ...READ MORE

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

what is containership or nesting in C++?

According to what I believed, a class ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
192 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
288 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
218 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
416 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
307 views
0 votes
0 answers

How to pass reference-to-function into another function

Using function pointers as arguments for other ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
220 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
399 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
346 views
0 votes
0 answers

Inbuilt __gcd(A,B) function in C++

I recently learned about a c++ specia ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
242 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
529 views
0 votes
0 answers

How to access static members of a class?

I'm learning C++ and Qt, but even the simplest code that I copy and paste from a book produces problems. On Ubuntu 10.04, I'm using g++4.4.2 with the QtCreator IDE.  Is there a distinction between the syntax of the g++ compiler and those of other compilers?  When I try to access static members, for example, something always goes wrong. #include <iostream> using namespace std; class A { ...READ MORE

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

How to copy turbo c++ output?

How can I replicate the output of Turbo C++?  I had already Googled the issue, but in vain.  It suggests to either print scrn and paste or right click, select all, and paste.  I tried both, but neither worked.  The issue is that it simply copies what is on the current screen.  But I want the entire screen from the start.  (Alt+printscrn is also ineffective).  What should I do in this situation? printScrn Alt+printScrn markall None of them are operational!! I can't assist you if you require this archaic technique of programming for whatever reason, but I'd want to find a solution.  I tried forwarding the output stream to the file in this manner, but it did not work. #include<iostream.h> #include<conio.h> #include<stdlib.h> const int max=50; class dequeue{ int dq[max],r,f,c,x,i; public: dequeue(); void insertRear(); void insertFront(); void ...READ MORE

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

How to use enums in C++

Suppose we have an enum like the following: enum Days ...READ MORE

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

Differences between C++ string == and compare()?

I just read some recommendations on using std::string ...READ MORE

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

What does the C++ standard state the size of int, long type to be?

I'm seeking for specific information on the sizes of basic C++ types.  I understand that it is determined by the architecture (16 bits, 32 bits, or 64 bits) and the compiler. But are there any C++ standards? On a 32-bit architecture, I'm using Visual Studio 2008.  This is what I get: char : 1 byte short : 2 ...READ MORE

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

What does the C++ standard state the size of int, long type to be?

I'm seeking for specific information on the sizes of basic C++ types.  I understand that it is determined by the architecture (16 bits, 32 bits, or 64 bits) and the compiler. But are there any C++ standards? On a 32-bit architecture, I'm using Visual Studio 2008.  This is what I get: char : 1 byte short : 2 ...READ MORE

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

Sorting a vector in descending order

Should I  utilize  std::sort(numbers.begin(), numbers.end(), std::greater<int>()); or std::sort(numbers.rbegin(), numbers.rend()); // ...READ MORE

Jul 5, 2022 in C++ by Nicholas
• 7,760 points
1,858 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
470 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
911 views
0 votes
0 answers

Why doesn't C++ have a garbage collector?

First and foremost, I'm not raising this ...READ MORE

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

C++ Singleton design pattern

I recently came upon a C++ realization/implementation of the Singleton design pattern.  It looked like this (I took it from a real-life example): // a lot of methods are omitted ...READ MORE

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

How to choose between map and unordered_map?

Assume I wanted to map data that ...READ MORE

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

Why use #define instead of a variable

What is the purpose of the #define ...READ MORE

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

C++ printing boolean, what is displayed?

I print a bool to an output stream like ...READ MORE

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

Static vs dynamic type checking in C++

I'm curious in the differences between static ...READ MORE

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

take string input using char* in C and C++

I'm having trouble accepting a string (actually a character array) as input.  Consider the following declaration: char* s; I have to input a string ...READ MORE

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

How to use c++ swap function?

It is OK to write swap(a,b); There is an issue when I write swap(&c[0],&d[0]);.  Can anyone explain why? #include<iostream> #include<algorithm> using namespace std; int main(void){ ...READ MORE

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

Reverse a number without converting it to string in C++

I'm attempting to write a programme in C++ to reverse a number. It works well with numbers like 1234, but when I try to enter a number like 5430, it displays 345, and the same with numbers that begin with zero, such as 0234, which displays 432. Could someone please explain how to deal with zeros at the beginning and end of a sentence? I simply need to save the number without converting it to a string. #include<iostream> using namespace std; int main(){ ...READ MORE

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

Infix to Postfix notation C++

Hello there, Stack.  I'm currently learning C++ and trying to create an RPN converter.  But I'm having difficulties.  Hopefully, I'll be able to describe the issues in detail.  For stacking my operators, I'm using an array.  Let's look at the example "5 + 8."  When it comes down to: else if(infix[i] == '+' or infix[i] == ...READ MORE

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

Is the std::set iteration order always ascending according to the C++ specification?

According to what I've read, std::set in ...READ MORE

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

Deep copy vs Shallow Copy

What's the distinction between deep and shallow ...READ MORE

Jun 29, 2022 in C++ by Nicholas
• 7,760 points
316 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
752 views