Latest questions in C++

0 votes
1 answer

How to reverse a number in C++?

#include <iostream> using namespace std; int main() { int n; cin>>n; int ...READ MORE

Oct 28, 2024 in C++ by kavya
331 views
0 votes
0 answers

undefined reference to `get_string' cs50 library

i am having this problem it tells ...READ MORE

Sep 16, 2023 in C++ by Mostafa

edited Mar 5 163 views
0 votes
0 answers

fatal error: cs50.h (c language library) : No such file or directory

I am trying to use cs50 library ...READ MORE

Sep 16, 2023 in C++ by Mostafa

edited Mar 5 176 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
• 63,600 points
970 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
• 5,430 points
871 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
• 5,430 points
1,237 views
0 votes
0 answers

#defining constants in C++

In various C code, I see constants ...READ MORE

Aug 26, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 38 views
0 votes
0 answers

Is it possible to get a single element of a set in C++ STL?

I have the following C++ code with ...READ MORE

Aug 26, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 35 views
0 votes
0 answers

Fast input/output in c++

In a programming question, I need to ...READ MORE

Aug 26, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 59 views
0 votes
0 answers

What is the difference between private and protected members of C++ classes?

What distinguishes C++ classes' private and protected ...READ MORE

Aug 26, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 34 views
0 votes
0 answers

Confused with object arrays in C++

I originally studied Java, and I'm currently attempting to transition to C++.  I'm having some trouble getting arrays to function properly. Right now, all I'm attempting to do is build an array of the object "Player" and add one to it.  But I encounter a problem. Player* players = new Player[1]; players[0] = new ...READ MORE

Aug 25, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 30 views
0 votes
0 answers

When should you use 'friend' in C++?

I like the concept of the << ...READ MORE

Aug 25, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 40 views
0 votes
0 answers

Rules for C++ string literals escape character

What are the string literals' escape character rules?  Are all the characters that are escaped listed somewhere? In particular, gedit colours the following three values differently when I use the symbol in a string literal. I was attempting to generate a std::string from a literal consisting of the character 0, the null character (0), and the character 0.  However, the syntax highlighting warned me that this would result in just two characters, such as the letter 0 followed by the null character (\00, aka \0). Is the following the best course of action for the solution to just this one issue: std::string ("0\0" "0", 3) // ...READ MORE

Aug 25, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 54 views
0 votes
0 answers

In C++, what is the difference between a method and a function

I'm making an effort to use the ...READ MORE

Aug 24, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 30 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
745 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
931 views
0 votes
0 answers

c++ custom compare function for std::sort()

I want to create custom compare function ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 63 views
0 votes
0 answers

Alternative function in iostream.h for getch() of conio.h?

I'm attempting to hold the screen on ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 64 views
0 votes
0 answers

Why can we not access elements of a tuple by index?

tuple <int, string, int> x=make_tuple(1, "anukul", 100); cout ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 59 views
0 votes
0 answers

Remove a key from a C++ map

I want to take a key out ...READ MORE

Aug 23, 2022 in C++ by anonymous
• 7,760 points

edited Mar 4 58 views
0 votes
0 answers

Generic Classes in C++

Generic Classes was the topic I was reading. I at one point became immobile.  Here is the relevant code: template <class StackType> class stack { ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 56 views
0 votes
0 answers

How do you declare an interface in C++?

What is the best way to build ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 30 views
0 votes
0 answers

Is it more efficient to copy a vector by reserving and copying, or by creating and swapping?

I'm attempting to efficiently duplicate a vector. I see two potential strategies: std::vector<int> copyVecFast1(const std::vector<int>& original) { std::vector<int> newVec; ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 34 views
0 votes
0 answers

How to convert C++ Code to C

I've got some C++ programme. Numerous classes, ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 28 views
0 votes
0 answers

Passing vector by reference

Using standard C arrays, I would carry out the following: void do_something(int el, int **arr) { ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 59 views
0 votes
0 answers

When should you use a class vs a struct in C++?

When using C++, when is it preferable ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 31 views
0 votes
0 answers

Alternative to itoa() for converting integer to string C++?

If I use itoa() to convert an ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 71 views
0 votes
0 answers

Printing prime numbers from 1 through 100

The following prime numbers are printed out by this C++ code: 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 73 79 83 89 97. However, I don't believe that is how my book would prefer it to be written.  It makes a reference to the square root of a number.  I thus tried switching my second loop to for (int j=2; jsqrt(i); j++), but it did not produce the desired outcome. How would I modify this code to make it the way my book desires it to be? int main () { ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 56 views
0 votes
0 answers

Why do we need abstract classes in C++?

I recently learnt about polymorphism in my ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 55 views
0 votes
0 answers

C++11: How to alias a function?

If I have a class Foo in ...READ MORE

Aug 23, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 36 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
995 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
818 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
484 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
659 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
487 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
611 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
1,468 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
942 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

edited Mar 4 59 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
887 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
735 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
711 views
0 votes
0 answers

How does sizeof know the size of the operand array?

It could be a silly question, but ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points

edited Mar 4 64 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
752 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
661 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
565 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
512 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
719 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
513 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
1,152 views