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
-
5
votes2
answers458
viewsDoubt in displacement of bits in C
My question is regarding the following excerpt from a code: #include <stdio.h> int main(void){ int teste = 0, x0 = 0, x1 = 0, x2; x2 = 1; teste = ((x0|x2) | (x1|x2) << 1); printf("Valor…
-
5
votes3
answers4668
viewsHow to compare one to one all the elements of two vectors?
Having two vectors of int of the same size, there is some native language function comparing the position x of the first vector with the position x of the second vector, doing this for all positions…
c++asked 8 years ago Lucas João 95 -
5
votes1
answer241
viewsReference error in DLL
I am creating a DLL that needs to export 11 CEN/XFS functions, but there is a function that consumes a header file. I think the mistake is in consuming a method from a header that is not stated in…
-
5
votes1
answer227
viewsReturn 0 on Linux and Windows
I am starting the ADS course and my programming teacher insists on using the return 0 at the end of the function. Most use Windows, I realized that the return 0 is required on Windows but on Ubuntu…
-
5
votes4
answers13368
viewsWhat are files with extension . cpp and . h?
What are these files with extensions .cpp and .h? How they interact with each other ?
-
5
votes1
answer157
viewsIs overlapping polymorphism mandatory?
In overlapping polymorphism is it mandatory that the method of a mother class that will be superimposed on a subclass be abstract? Is there an exception for some POO language?
-
5
votes3
answers337
viewsWhat’s wrong with allocating memory with new and then not erasing?
What can happen if I use the new to allocate memory and then don’t release it? And when it is in the situation below, that I can not erase the allocated memory, because I need to return, what I do?…
-
5
votes2
answers134
viewsWhat is the problem of returning a local variable?
What can happen if I return a local variable? I read on the internet that it is not a good idea to return a local variable. Maybe why the variable when exiting the function is deleted? Example:…
-
5
votes3
answers104
viewsWhy do you use a vector with a name on it?
would like to know the function of using a name within a vector? char chave[NUM_LETRAS + 1]; int frequencias[NUM_LETRAS]; int frequencias2[NUM_LETRAS]; char codificado[MAX_STR]; char…
-
5
votes2
answers104
viewsCommunication of c# and c++
How can I make the C# code call a variable that is in a C++ file for example. Knowing that I am using Visual Studio. Code C++: #include "stdafx.h" #include <iostream> int main() { int test =…
-
5
votes2
answers140
viewsHow to verify if a type is numerical in C++?
Let’s assume I have a function: template<class T> T soma(const T& x, const T& y) { static_assert(/*O tipo é for numérico?*/, "Tipo de argumento inválido, O argumento precisa ser…
-
5
votes1
answer123
viewsWhy is it possible to store a string on a char pointer?
Why char stores a single character and the pointer points to its value in memory, so it shouldn’t have just one character? Example: char *str = "Ola"; Why str does not store only one character?…
-
5
votes1
answer112
viewsIs it prudent to use several paradigms in a C++ project?
Would it be advantageous to use several paradigms in a project in C++? For example, in a certain part of the code I use reactive Programming, in other parts I use OOP, and in other parts I use…
c++ oop encoding-style functional-programming paradigmsasked 5 years, 11 months ago Strawberry Swing 177 -
5
votes1
answer90
viewsUsing template, why use the const modifier in this variable (C++)?
#include <iostream> using std::cout; using std::endl; template <unsigned int i> struct Fibo{ static const unsigned result = Fibo<i-1>::result + Fibo<i-2>::result; }; template…
-
5
votes5
answers391
viewsConcatenation in C
I’m doing a C algorithm to shut down some machines. This is my algorithm: #include <stdio.h> #include <stdlib.h> #include <conio.h> main() { char vetor[2][15] = {"192.168.2.200",…
-
5
votes1
answer65
viewsWhy does Std::Ceil produce different results for float and double?
Follows the code: #include <iostream> #include<math.h> using namespace std; int main() { float calculo = 4.347 * 20 * 100; double calculo2 = 4.347 * 20 * 100;…
-
5
votes1
answer168
viewsWhy does Std::Cout use <<?
I am very beginner in language, maybe I am being rushed, but I would like to understand why std::cout and std::cin use respectively << and >> different from its "mother language" C,…
-
5
votes2
answers140
viewsI cannot use the value passed in argv in the program call
When I type b in the call of the program he does not return me the Bom dia. I would like to understand what is wrong in my code. Follow the program below. #include <stdio.h> int main (int…
-
5
votes1
answer56
viewsCan LLVM be used with the C language?
I’m studying compilers and I’m using the C language and learning about LLVM but all examples are in C++ language. The question is whether I can use the LLVM with the C language and how can I start a…
-
5
votes2
answers111
viewsShould I avoid repeated access to the same method within a loop?
I worry about the final performance of an executable, at the same time I don’t want to penalize the programmer with excessive or unnecessary care in the code. In the code below, for example, it will…
-
5
votes1
answer209
viewsIf C/C++ are native languages then why do they need runtimes?
Usually the first thing that came to my mind when I heard the term native language, was a program that ran independent of operating system, communicating directly with hardware, I always developed…
-
5
votes1
answer96
viewsWhat are the criteria for failbit and badbit in a Std::istream?
In a C++ exercise, it is proposed to store a data (numeric, integer - eg.: 4 or -3650) entered by the user through the console. This is an exercise to deal with exceptions and "defensive…
-
5
votes1
answer73
viewsstruct character array
I’m having to remember programming in c++ to teach a beginner class in programming logic. Subject that I haven’t seen in years. One struct was declared however when entering a string, the stream…
-
5
votes1
answer239
viewsProblem with file reading . WAV
Hi, I’m trying to read a file. 5s wav filled with "silence" to test the code in C. I was able to read the header but while trying to extract the date field where it contains the content itself (…
-
5
votes1
answer88
viewsWhat is the lowest number of irrigators (circles) needed to cover the surface of a foliage (rectangle)? (competitive programming)
I participated in a test and, in one of the problems, I did not get the total score of the question, one of the test cases gave Wrong Answer, but I could not identify exactly my error. The statement…
-
5
votes0
answers60
viewsWhat is and what is the advantage of using "span<T>"?
C++20 has a new type std::span. External libraries as GSL also provide C++14 and C++17 compliant implementations. Seeking to understand what a span<T>, I stumbled upon the following…
-
4
votes3
answers273
viewsHow to implement Std::to_string for floating point?
This question may seem more like a request, but I’ve been researching it for 2 months and I don’t know how to solve it. I need to implement the std::to_string in C++ (headless) in a way that accepts…
-
4
votes2
answers144
viewsHow to make a constructor equal to Qobject?
When a new question arises from an old question, I want to know how to create a class equal to QObject. Basically, I want to know: How to make a copy constructor that does not accept "assignment…
-
4
votes3
answers869
viewsTime measurement in Windows
I would like to know how best to measure the running time of a programme in C++. I found several solutions on the internet, each with an approach. Suggestions?
-
4
votes1
answer1144
viewsResize components when enlarging window
How can I resize the components inside the QWidget when enlarging the window? Example of how it looks:…
-
4
votes2
answers461
viewsQMYSQL driver not Loaded Qtcreator
I am trying to connect to the database with Qtcreator as follows: this->db = QSqlDatabase::addDatabase("QMYSQL"); this->db.setHostName("localhost"); this->db.setDatabaseName("Pessoa");…
-
4
votes2
answers2140
viewsHow to "clean" static variables?
In C++ static variables are very important. Let’s assume that I want to make a factorial that uses recursion. unsigned long long int RecursionFatorial(unsigned int fator) { static long long int…
-
4
votes2
answers211
viewsDisplays hexadecimal value in cmd.exe
I’m trying to show the sharp letter 'is' on cmd.exe through the hexadecimal, but the printf() only shows the value of the character itself. I’m trying the following: unsigned char eh = 0x82;…
-
4
votes2
answers5586
viewsHow to move, rotate or scale an Object on its local axis in Opengl?
Hello, I have a class HTransform which stores a matrix, position, orientation and scale of each object, this class is the base class of each Object or entity. I made one function to move the Object…
-
4
votes1
answer491
viewsHow to create a Managed Thread in C++ similar to the example in C#
In C# I use the following code to create Managed Thread: Thread thread = new Thread(new ThreadStart(minhaFuncao)); In C++ i made: using namespace System::Threading; . . Thread^ thread = gcnew…
-
4
votes1
answer437
viewsPointers with methods, where am I wrong?
Creating a class that will have two methods one assign another to print vectors with public and then call this method no main. I was able to make it this far with the method baby Steps. Where I’m…
-
4
votes2
answers92
viewsHow to use Gtkmm-3 and standard input together?
I want to make a program with Gtk that reads data from the standard input and interprets making drawings in a DrawingArea. The concept is simple, but I came across a problem: after I called…
-
4
votes1
answer81
viewsQsharedpointer Definition and Function
From what I understand, the Qsharedpointer is a smart Pointer, ie, a pointer that offers automatic garbage collection. If possible I would like a code that better explains this, including when I…
-
4
votes1
answer87
viewsQvector to Qimage
I have to turn one QVector 2d in a QImage to display the image on a label. The QVector in the case of an array of integers with a value of 0 to 255 representing an image in PGM or PPM, this vector…
-
4
votes2
answers1760
viewsHow to format monetary values with C++?
I would like to present values formatted as currency, with thousands and cents separators. I would like for example, 56000/12 present 4.666,67. I can present 4,666.67. Would there be some way to…
-
4
votes1
answer213
viewsRepaint screen every little time without crashing - C++
I have the following situation: I have to repaint the screen every little while so that objects on the screen move on their own, but this has to occur so that the program does not lock. I tried to…
-
4
votes1
answer151
viewsQt String Encoding Problem
I’m having a problem encoding strings on Qt. By showing something in a QMessageBox or give a drawText in a paintEvent, my strings come out badly formatted, as if they were not in the correct…
-
4
votes2
answers4941
viewsHow to capture keyboard action without pausing the C++ program?
How do I capture a keyboard action without pausing the program? For example: char tecla; do{ scanf("%c", &tecla); printf("%c",tecla); }while(tecla != '0'); I wanted it to be on a loop, but when…
c++asked 10 years ago Antony Alkmim 1,715 -
4
votes1
answer612
viewsConnect and disconnect Internet?
I would make two . exe basic, one would be to disconnect the Internet and open one program and the other would be to just connect to the Internet. The part of opening the program I know, now…
-
4
votes1
answer523
viewsIs it possible to use pointers in VB.NET?
Is it possible to use VB.NET pointers? If so, how do they work? An example in C++: CSR = ConfigurarInterfaceDeRede(randInt(0,999999),CodAtivacaoSAT,(char*)xml); int a; int *p; p = &a; How would…
-
4
votes2
answers329
viewsStore SMS message in variable
I’m having trouble saving a text message in a variable. The idea is to send an SMS with a command and later use a conditional operator to activate or deactivate a relay. But I can’t save the SMS…
-
4
votes3
answers880
viewsInteger for String
In QT Creator 5, how do I convert Integer to string? In Visual Studio 2012 there was the command: std::to_string(10); But it doesn’t work on QT. I tried to: #include <QCoreApplication>…
-
4
votes2
answers775
viewsHow to Vector/Array integers indexed by strings?
How do I vector/array integer numbers with strings as index? Something that in Lua would be: vetor = { ["eu"] = 10, ["voce"] = 11, } ps: It will be dynamic, so it will not have a fixed size. ps²:…
c++asked 9 years, 9 months ago Gabriel Sales 1,257 -
4
votes3
answers1952
viewsHow to get a text from a Qlineedit in Qt?
For example, I have a LineEdit, when I press a button I want to pick up what I wrote on this LineEdit and store a QString.
-
4
votes1
answer314
viewsReading entire file
I am trying to read a simple file, which contains only two lines, but the program shows only one. The program: #include <iostream> #include <fstream> using namespace std; int main() {…
c++asked 9 years, 6 months ago Gabriel Sales 1,257