Trending questions in C++

0 votes
1 answer

Passing a 2D array to a C++ function

There are three ways to pass a ...READ MORE

Aug 2, 2022 in C++ by Damon
• 4,960 points
10,991 views
0 votes
1 answer

Suggestions of excellent examples of real C/C++ code

I'd like to particularly bring up memcached.  ...READ MORE

Dec 17, 2022 in C++ by narikkadan
• 62,980 points
151 views
0 votes
0 answers

Best way to split a vector into two smaller arrays?

I'm attempting to divide a vector into ...READ MORE

Nov 17, 2022 in C++ by Ashwini
• 4,890 points
374 views
0 votes
0 answers

Check if element found in array c++

How can I see if the element ...READ MORE

Nov 17, 2022 in C++ by Ashwini
• 4,890 points
160 views
0 votes
1 answer

casting int to char using C++ style casting [duplicate]

Even though the precision is lost, yo ...READ MORE

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

How does #include <bits/stdc++.h> work in C++? [duplicate]

#include <bits/stdc++.h> is a precompiled header implementation ...READ MORE

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

Why can't the switch statement be applied on strings?

The reason for this is due to ...READ MORE

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

Use of min and max functions in C++

The functions fmin and fmax are designed ...READ MORE

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

Where are the Microsoft Visual C++ 2015-2022 Redistributable (x64) packages installed?

They are, in my opinion, at their best. C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Redist\MSVC It's worth noting ...READ MORE

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

Is there any built-in factorial function in c++?

Although no C function is written particularly for computing factorials, the C math package allows you to compute the gamma function. Because (n) Equals (n-1)!  Using tgamma of i+1 on positive integers returns i!. for (int i = 1 ; ...READ MORE

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

What is the difference between operator overloading and operator overriding in C++?

Some people use the latter word to ...READ MORE

Aug 2, 2022 in C++ by Damon
• 4,960 points
1,233 views
0 votes
0 answers

get absolute value without using abs function nor if statement

How might I obtain an integer's absolute ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
561 views
0 votes
0 answers

Read whole ASCII file into C++ std::string

I need to load an entire file ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points
284 views
0 votes
0 answers

Correct way to work with vector of arrays

Could someone please explain how to work ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points
171 views
0 votes
0 answers

Making a class abstract without any pure virtual methods

I take a class where we watch ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
277 views
0 votes
0 answers

Is C++ considered weakly typed? Why?

C++ has always struck me as one ...READ MORE

Aug 8, 2022 in C++ by Nicholas
• 7,760 points
601 views
0 votes
0 answers

Remove elements of a vector inside the loop

I am aware that there are questions like this one, but I was unable to use them to help me decipher my code.  I just want to remove or delete one element from a vector by running a loop over its property.  How can I go about doing that?  I tried the following code, but I got an ambiguous error message: 'operator =' function is unavailable in 'Player’. ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
182 views
0 votes
0 answers

Why is the size of an empty class in C++ not zero?

Why does the following output 1? #include <iostream> class Test { }; int ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
154 views
0 votes
0 answers

Differentiate between function overloading and function overriding

Differentiate between function overloading and function overriding ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
126 views
0 votes
0 answers

What are the differences between struct and class in C++?

I now want to understand the distinctions ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
124 views
0 votes
0 answers

How do I set up Visual Studio Code to compile C++ code?

Although the Visual Studio Code editor from ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
114 views
0 votes
0 answers

What is the difference between std::list<std::pair> and std::map in C++ STL?

What distinguishes std::list<std::pair> from std::map? Does the ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
109 views
0 votes
0 answers

What is the point of function pointers?

The purpose of function pointers is difficult ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
107 views
0 votes
0 answers

std::cin input with spaces?

#include <string> std::string input; std::cin >> input; The user want to type "Hello World."  However, cin fails to recognise the space between the two words.  How do I get Cin to see the entire Hello World? I'm trying this using structs, and cin.getline doesn't appear to work.  This is my code: struct cd { ...READ MORE

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

memory allocation for objects

In C++, a variable like int x ...READ MORE

Aug 16, 2022 in C++ by Nicholas
• 7,760 points
131 views
0 votes
1 answer

What is dynamic initialization of object in c++?

Dynamic initialization occurs when the initialization value is unknown at compile time.  To initialise the variable, it is calculated at runtime. Example, int factorial(int n) { ...READ MORE

Aug 2, 2022 in C++ by Damon
• 4,960 points
723 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
1,608 views
0 votes
0 answers

What does '&' do in a C++ declaration?

As a C person, I'm attempting to comprehend some C++ code.  The declaration of my function is as follows: int foo(const string &myname) { cout ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
86 views
0 votes
0 answers

How to end C++ code

I want my C++ code to terminate  ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
81 views
0 votes
0 answers

Why was the ampersand chosen as the symbol for references in C++?

Does anyone know why the ampersand was ...READ MORE

Aug 16, 2022 in C++ by Nicholas
• 7,760 points
97 views
0 votes
0 answers

How does "this" cascading work?

The following class interface I have is: ...READ MORE

Aug 16, 2022 in C++ by Nicholas
• 7,760 points
85 views
0 votes
0 answers

declaring a priority_queue in c++ with a custom comparator

I'm attempting to declare a priority queue of nodes using the comparator function bool Compare(Node a, Node b) (which is outside the node class). I presently have the following: priority_queue<Node, vector<Node>, Compare> openSet; I'm receiving Error: "Compare" is not a type name for some reason. Adding priority_queue<Node, vector Node>, bool Compare> to the declaration. gives me the error 'Error: expecting a '>' I've also attempted: priority_queue<Node, vector<Node>, Compare()> openSet; priority_queue<Node, ...READ MORE

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

How to convert an instance of std::string to lower case

#include <algorithm> #include <cctype> #include <string> std::string data = "Abc"; std::transform(data.begin(), ...READ MORE

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

Efficient way to return a std::vector in c++

When delivering a std::vector in a function, how much data is duplicated, and how much of an optimization will it be to place the std::vector in free-store (on the heap) and provide a pointer instead, i.e. is: std::vector *f() { std::vector *result = new ...READ MORE

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

(->) arrow operator and (.) dot operator , class pointer

In C++, we know that given a class pointer, we use the (->) arrow operator to access the members of that class, as seen here: #include <iostream> using namespace std; class myclass{ ...READ MORE

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

What's the difference between constexpr and const?

Variables are protected from modification in your ...READ MORE

Aug 5, 2022 in C++ by Damon
• 4,960 points
431 views
0 votes
0 answers

How to Access Subgraphs of an Existing Graph in Boost

I read a graph using read graphviz() ...READ MORE

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

Is there a maxheap in the C++ standard library?

I understand that the std::priority queue class ...READ MORE

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

memory allocation for objects

When we instantiate a variable in C++, ...READ MORE

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

how to print \" in C++

I need to print the following string: std::string("-I\"/path/to/dir\" "); Basically, I need to accomplish this since I am generating C++ code using C++ code. I want to use an ofstream to write the above string, so something like ofstream fout; fout << the_string ...READ MORE

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

In C, are arrays pointers or used as pointers?

First, look at this code When this is ...READ MORE

Aug 11, 2022 in C++ by krishna
• 2,820 points
129 views
0 votes
0 answers

How to generate a random number in C++?

I'm attempting to develop a dice game, and I need random numbers to represent the sides of the die.  I can make a number between 1 and 6).  Using #include <cstdlib> #include <ctime> #include <iostream> using namespace ...READ MORE

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

Difference between 'struct' and 'typedef struct' in C++?

In C++, is there any difference between: struct Foo ...READ MORE

Aug 8, 2022 in C++ by Nicholas
• 7,760 points
245 views
0 votes
1 answer

How do I create an array of pointers?

Student** db = new Student*[5]; // To allocate ...READ MORE

Aug 5, 2022 in C++ by Damon
• 4,960 points
356 views
0 votes
0 answers

What is a stream in C++?

I've been hearing a lot about streams, ...READ MORE

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

Confused with object arrays in C++

I have some Java knowledge and now ...READ MORE

Aug 11, 2022 in C++ by krishna
• 2,820 points
87 views
0 votes
0 answers

How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?

I wanna create a program that can ...READ MORE

Aug 5, 2022 in C++ by krishna
• 2,820 points
345 views
0 votes
0 answers

How can I get double quotes into a string literal?

I used the printf() command to produce the output seen below: printf("She said time flies like an arrow, ...READ MORE

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

std::string length() and size() member functions

While reading the responses to this topic, ...READ MORE

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

How to convert string to char array in C++?

Simplest way I can think of doing ...READ MORE

Jun 20, 2022 in C++ by Damon
• 4,960 points
2,386 views