Most voted "c++" questions
C++ is a typed, compiled, multi-paradigm, intermediate level, and general purpose programming language. It should not be confused with the language C. It was developed in the early 1980s by Bjarne Stroustrup as an extension of C. Its evolutionary features include type checking, support for automatic resource management, object orientation, generic programming and treatment of exceptions, among others.
Learn more…2,348 questions
Sort by count of
-
4
votes1
answer97
viewsDoes it pay to store the value of a struct member in a local variable?
I see several programmers doing this. Instead of accessing a member of a struct directly, it copies the value to a local variable to the function and uses this variable. Is there performance gain in…
-
4
votes1
answer560
viewsC++ - Sort particular points of a rectangle in a vector?
I have a project in c++ where I should map regions of an image using the mouse click. The point is that I should get the mapping points in a specific storage order, as in the image below: my problem…
-
4
votes1
answer234
viewsUse of assert instead of if
I was reading a book about data structures implemented in C++ and here the author presents the following code snippet: T& operator[](int i) { assert(i >= 0 && i < length); return…
-
4
votes1
answer3755
viewsFunction pointer in a C++ class
I’m having trouble putting a pointer to a function in a class: int Menu::validaescolha(){ cout << 1232; return 1; } int Menu::inicial(){ int (Menu::*funcs)() = &Menu::validaescolha;…
c++asked 7 years, 9 months ago Rafael Bernardo 136 -
4
votes1
answer2500
viewsHow to take the maximum/minimum value of an integer in the C language
Talk people! Is there a function in the C language that takes the maximum/minimum value of an integer?
-
4
votes2
answers137
viewsIs it possible that a class attribute is the class itself?
I’m starting to learn C++ Object oriented, and I have to make an algorithm using chained lists. In C, I used a structure that had as one of the attributes a pointer to the structure itself. I wonder…
-
4
votes1
answer240
viewsWhy are there so many parentheses in macro?
Seeing this, it intrigues because it needs those parentheses that seem unnecessary. What is their functionality? #define SUB(x, y) ((x) * (y))
-
4
votes1
answer2537
viewsWhat is the difference between pointer to vector and pointer to variable?
int A; int* pA = 1; int Vect[2] = {1,2}; int* pVect; pA = &A; *pA = 2; pVect = Vect; pVect[0] = 10; In the case I have a pointer to a variable and then to an array, and I want to change its…
-
4
votes1
answer763
viewsHow to perform operations with really large numbers in C/C++?
How to perform sum operations with really large numbers? Numbers that can reach 50 or 1000 digits. Is it necessary to install a library? How to install this library in Ubuntu? You can post some…
-
4
votes1
answer66
viewsSpecialize only one template class method
I own 2 basic class types, Classea and Classeb. Classea has a method that generates an integer, and Classeb has a method that generates a Classea. I would like in the method of a Classec, if the…
-
4
votes1
answer1480
viewsAfter all, why use C when programming in C++?
I’m learning C++ and I can’t understand why people think C knows C++? Or are the differences between the two despicable? I know the syntax is similar, but C++14 does things that C doesn’t, and aside…
-
4
votes1
answer183
viewsHelp with Signal and slots (connect in another file slot)
Good morning dear, created a project (Qt Widget Application) with Qt Creator (Qt 5.6.1). The project has the following structure: myproject.pro Headers dialogform. h mainwindow. h Sources…
c++asked 7 years, 10 months ago Juliano Gomes 69 -
4
votes1
answer2044
viewsCreating processes with Fork
I am creating a sequence of processes through the command fork, but when I went to list the processes generated by the code, I found that there was a greater amount than I had created. Because of…
-
4
votes1
answer842
viewsWhat is and what is the sockaddr_in structure for?
Lately I’ve been wanting to program a network sockets in C++ but as the matters on the internet about it are a little limited coming to show only how to program the sockets without explaining in…
-
4
votes0
answers58
viewsIsn’t the value of an unassigned int variable in C++ 0 (zero)?
I’m having my first serious contact with C++. I wanted to see what would happen if I added up a value int of a variable assigned with another without assigning, and see what happened: #include…
-
4
votes1
answer350
viewsHow to initialize an array in this constructor?
I’m trying to initialize a array with 0, however the compiler is generating error, I know I can initialize as well: Constructor() : Value1(0), Value2(0), Initialized(false), vSh(false) { Name[100] =…
-
4
votes3
answers138
viewsIn structures (struct) is it necessary to use getters and setters or only in classes (class)?
It is necessary to use setters and getters in structures to maintain good practice or is needed only in classes?
-
4
votes1
answer94
viewsWhy is the exit 16?
#include <iostream> int main() { int x, y = 3; x = (++y) + (++y) + (++y); std::cout << "y = " << y << std::endl; setlocale(LC_ALL, ""); std::cout << "O valor de x é "…
c++asked 6 years, 9 months ago João Victor 43 -
4
votes1
answer101
viewsPass by reference printing garbage in the vector
Guys, I made a simple code, but I have a problem. I made a function "increase" to increase the size of a vector; the function receives the vector and passes the values of that vector to an auxiliary…
-
4
votes1
answer687
viewsWhat are the most common C++14 compilers on Linux?
What are the most common free compilers on Linux to compile C++14? " Most common" in the sense of most used and available in several distributions. I am using CENTOS and need to compile code that…
-
4
votes1
answer197
views -
4
votes1
answer421
viewsHow to copy integer matrix for Mat type in Opencv?
Would you like to know how to copy an integer array to an Opencv Mat type data ? The following is an example I created to illustrate my goal, which corresponds to a given user generated matrix (…
-
4
votes1
answer220
views -
4
votes1
answer112
viewsHow to print a hexadecimal value in high box?
I made a program in C++ that reads a number and prints it in hexadecimal, follows the code below. #include <iostream> using namespace std; int main(void) { int n; cin>>n;…
-
4
votes2
answers1091
viewsOperation of the new operator
I wanted to understand basically what the logic behind the objects of the classes that use the operator new for example, I have the following program in D: import std.stdio; class Hello { public…
-
4
votes1
answer129
viewsWhen is the destroyer of an object called in C++?
Let’s assume I have a function: std::string empty_string() { std::string x{ "" }; return x; } As normal as it sounds, it gets a little fuzzy when we think: When the destroyer of the object x is…
-
4
votes1
answer313
viewsC/C++ standard libraries
What’s the downside of using libraries standards such as the function getch() and the library conio.h, What is the downside of using such libraries from a development point of view? More precisely…
-
4
votes1
answer395
viewsHow to vector code in C++?
Would you like to know how to vector code in C++ ? because the material I found on the internet is a bit excasso. I understand as vectorization the use, not only of vectors, but of doing in a single…
-
4
votes1
answer4254
viewsC, C++, C#? Why should a beginner start learning?
I am 17 years old and I am learning Java, when I feel that I already master the language I plan to migrate to . NET! What is recommended to start C, C++ or C#? Thanks for the help ^^
-
4
votes1
answer133
viewsC++: Addition of ". cpp" implementations in Visual Studio and GCC
In C++, what is observed in a quick internet search is the orientation that only ". h" files should be included. A sample of this can be observed here and especially here. In Visual Studio, the…
-
4
votes1
answer97
viewsWhat does the ">" operator do in the middle of an arithmetic expression in C++?
I found this line of code in a proposed solution to a certain problem. excedente = a % 10 + b % 10 + excedente > 9; My point is, what function is that the > 9 makes this line me specific?…
-
4
votes1
answer175
viewsProblems with scanf and printf in C++
I have a program in which I need to store an array of a music class that generates a list of the songs and their characteristics. The problem is that at the time of the printing method it generates…
-
4
votes1
answer213
viewsDouble type variable precision problem
I’m solving the 1021 issue of the Judge URI, but I have a problem with the accuracy of my input value. Follow the base code: #include <iostream.h> int main(){ double a; cin >> a; } The…
-
4
votes1
answer83
viewsIs it possible to use logical operators within "Cout"? - C++
I would like to know if you have how to use logical operators and/or ternary operator within the Cout, as well as is possible within the printf. int main () { int n = 5; //Como fazer isso (Funciona)…
c++asked 5 years, 4 months ago Vitor Carlos 120 -
4
votes1
answer100
viewsWhat is Monomorphization?
I was reading that posting and I came across that term monomorphization I’d like to know: What is its meaning? When this process occurs? What performance gain/loss is obtained by this process?…
-
4
votes3
answers138
viewsWhy does the Endl exist in C++ and n already performs the same procedure?
I’m sorry if the question seems trivial, but I don’t understand why Endl in C++, since n already performs the same task. It wouldn’t be "reinventing the wheel"?
c++asked 4 years, 2 months ago Gabriel Bento 75 -
4
votes1
answer41
viewsHow to convert regex Pattern from C# to C++?
I’m trying to use C++ regex but I’m having some difficulties, one of them is that Pattern was in a C#code, and I know practically nothing of regex in C++, and so the code does not work as it should…
c++asked 3 years, 9 months ago Luiz Fernando 345 -
4
votes2
answers501
viewsWhen to dynamically allocate memory?
In C++ you can easily declare an object or variable like this: tipo_da_variável nome_da_variável; This type of statement is the easiest to use, but you can also use the new to dynamically allocate…
-
4
votes0
answers36
viewsWhat is "L" for before a string in C++?
I noticed that some frameworks and Engines require the string to be passed with L before the text. A Irrlicht Engine is an example. myObject->setLabel(L"my string"); What is the purpose of this L…
-
4
votes1
answer306
viewsSend two triangles to a Vertex Shader. Opengl, C++, GLSL
I am learning in college graphic processing with Opengl at C++. We are using the GLFW and GLEW libraries. My program consists of creating two triangles in different parts of the window. I created an…
-
4
votes1
answer112
viewsLogic of these bit-by-bit operations
It’s been a long time since I wanted to start in the world of emulators, I decided to stop trying to make an emulator of a complex system and start with a very basic one, a CHIP-8 emulator, which is…
-
4
votes1
answer216
viewsIs it good practice to use virtual functions in non-derivative classes?
When I was learning C++ I read in a book in the polymorphism chapter about virtual functions that the virtual keyword was meant to indicate that that function was going to be overwritten in another…
c++asked 6 years, 4 months ago Samuel Ives 1,676 -
4
votes1
answer142
viewsSort in C++ does not show the correct input value
I made a code to read 3 values, and with the sort() it sorts the values in ascending order and just below shows the input values. For example:-14 21 7 it sorts right but the output shows -14 7 21 //…
-
4
votes1
answer142
viewsWhat are the differences between macros and constexpr? When is it preferable to use one instead of the other?
I haven’t been in touch with C++, until I decided to create a project to test a solution. As I knew before, I created a macro to use a value as "constant" later, example: #define MAX_ENTRIES = 10…
-
4
votes2
answers76
viewsFind() function of the set library does not return whether or not it found
I’m writing a little program for a college exercise and I’m having second thoughts about find(). I must enter two integer numbers, check if the first number exists within the set previously defined.…
-
4
votes1
answer232
viewsfread(); problem in implementation
I have a simple problem. I can use the function fread normally to work with audio processing in C. In case I have 2 codes. The first reads a file . WAV (with fread) and saved in a .CSV. file This…
-
4
votes1
answer38
viewsUse of delete in an abstract class pointer
Reading the book A tour of C++, in a section on memory leakage, when I came across 3 statements regarding the code below: The implementation of Smiley may fail to delete pointer to mouth. The…
-
3
votes1
answer631
viewsHow to cast between base and derivative classes?
I have an exercise that says I have to create a foundation. This base has two derivatives. I have to cast the derived class(1) for the derived class(2) and the derived class(2) for the base class.…
-
3
votes1
answer442
viewsClass creation in C++
I am developing a project and need to create an internal class. I am obliged to create a . cpp and a . h?
-
3
votes1
answer4156
viewsCommand to exit the scope of a function (`break`equivalent)
How can I create an algorithm in C++ (using Qt) to abort code processing? I have to validate many different entries and I don’t want to keep creating if else if else. The code is ugly. Example, but…