Trending questions in C++

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
• 48,200 points
62 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
• 2,960 points
104 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
• 2,960 points
68 views
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
3,854 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
3,239 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
180 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
96 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
334 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
818 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
791 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
161 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
117 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
91 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
89 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
82 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
79 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
74 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
70 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
94 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
54 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
47 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
62 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
55 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
388 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
233 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
220 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
2,631 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
138 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
122 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
2,614 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
102 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
99 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
90 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
87 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
85 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
83 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
1,926 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
66 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
54 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
176 views
0 votes
0 answers

How do you properly use namespaces in C++?

I come from a Java background where ...READ MORE

Aug 8, 2022 in C++ by Nicholas
• 7,760 points
141 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
351 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
243 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
248 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
244 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
224 views
0 votes
0 answers

How come an array's address is equal to its value in C?

The pointer values and pointer addresses in ...READ MORE

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

How do you open a file in C++?

I want to open a file in ...READ MORE

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

What are Containers/Adapters? C++

What exactly are containers/adapters? I am familiar ...READ MORE

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

Insert object at index of vector c++

I have to add a new item to the existing object vector.  Although I am aware that an iterator must be used, I am not entirely sure how it operates. I need to insert a new item by name in the precise index that I found after some searching into an alphabetically sorted vector.  I have this, then. vector<Person>people; int index =54; Person temp; people.push_back(temp);//insert at end of ...READ MORE

Aug 5, 2022 in C++ by Nicholas
• 7,760 points
206 views