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
-
3
votes1
answer873
viewsC++: what SIGSEGV means
I’m making a dynamic numeric class, but when I test it, I get the message "Program recived Signal SIGSEGV". I know this is an error with pointers, but why does it occur and how I fix it? typedef…
c++asked 7 years, 4 months ago Felipe Nascimento 417 -
3
votes2
answers3378
viewsHow to print UTF-8 characters on the c++ console?
The console incorrectly displays accented characters. How to print them correctly (UTF-8)?
-
3
votes3
answers1906
viewsDecimal to octal conversion
I need to create an algorithm that converts decimal to octal, but my ta converting wrong, someone can help me as it would be right? #include <stdio.h> int decim(int n) { int i,a; int octal;…
-
3
votes0
answers92
viewsOptimization of poorly compiled
I set up Visual Studio to compile VC++ with /Ox and compiled this code (with more others that were omitted to simplify). union { unsigned long long u64 ; unsigned short u16[4] ; } x ; union {…
-
3
votes1
answer73
viewsAllocate memory with pointer or reference?
Is there any significant difference between these two methods? MyClass &ref = (*(new MyClass)); MyClass *ptr = (new MyClass);
-
3
votes1
answer2575
viewsInheritance with builders
I need to create a base class animal and 3 other hereditary classes of other animals. Each class must have its own function emitirSom. They should be invoked polymorphically through a vector. I…
-
3
votes1
answer77
viewsIs there inclusion mapping for ' #include "cmylib" '?
Reading that question, there is talk of the inclusion of headers in c++. In the answer accepted, section #include <filename>, the author speaks the following: it is common to have these names…
-
3
votes1
answer46
viewsAre there problems in declaring many noexcept functions?
I see a lot of code in C++14/C++17 where the programmer is sure that the function will make an exception, but does not report this pro compiler, perhaps because it may cause some problem when…
-
3
votes2
answers334
viewsRegex validating only normal and leap years in C++
I was trying to validate leap years using regex in C++. If the user type 28/02/1900, it would return valid. But if the same type 29/02/1900, he would return error. Searching, I found this regex that…
-
3
votes0
answers203
viewsCannot find -lalleg (DEV C++ and Allegro)
People every time I try to run this code is giving this error follows the code below: #include <allegro.h> int main() { allegro_init(); install_keyboard(); set_color_depth(32);…
-
3
votes1
answer60
viewsWhy do you have to add -pthread option when compiling with the Std thread library?
If in the main.cpp I use the library thread of std, to compile I have to use the following command: g++ main.cpp -pthread And even applies to Ang. This is the only case I know of the standard…
-
3
votes1
answer45
viewsEnum class not accepting check
Well I’m having a doubt I’m starting now at C++ I’m using an Enum class: enum class TYPE_ENTER { ENTER_OK = 0x1, ENTER_WARNING = 0x2 }; but when I compile the function there is error C2678 in the…
-
3
votes2
answers594
viewsInterest calculation
[Engelbrecht et al., 2012] Develop a program that receives from the user, the value of an application and the value of the initial interest rate. Whereas this interest rate increases 0.025% per…
-
3
votes1
answer109
viewsWhat is the functionality of this line of code?
I’m trying to translate the following code to C++: https://github.com/JohanLink/Ball-Balancing-PID-System/blob/master/pythonCodes/interface.py I wanted to understand what the following line does:…
-
3
votes2
answers69
viewsFor loop build error
I’m making a program that asks how many notes the user will type and after that, enters a 'for' loop asking what are the notes to type. Notes are stored in a array and finally the average. #include…
-
3
votes3
answers400
viewsHow to return 2 vectors of different types in C++
I perform a calculation and my result is saved in a vector<int> and a vector<string> How do I make my function return these two parameters in mine main()? int cracking(string chemform) {…
-
3
votes1
answer149
viewsWhat is the difference between memmove and memcpy?
What is the difference between the function memmove() and memcpy()?
-
3
votes1
answer53
viewsWhat’s wrong with using reinterpret_cast on C++?
I know what to use reinterpret_cast may cause indefinite behavior, but I still don’t understand why (I know it has something to do with the life cycle of the object and alignment of memory). I would…
-
3
votes3
answers2037
viewsRegex to validate certain date format
I was modifying a regex for a program in c++ that would validate the following date input form 29/feb/2000. Currently she was only accepting 29/02/2000 or 30/03/2017. I tried to add for the other…
-
3
votes1
answer198
viewsHow to create multi-line strings in C++
Have some way to print output, for example a text, without having to print line by line? For example, in Python: print(""" Meu nome eh Guilherme, tenho 19 anos, faço aniversário em Nov. Estudo o…
-
3
votes2
answers198
viewsForcing backreference in regex
These days ago I asked here about a regex that validates dates and how to force the separators to regex validated the following format: dd/mm/yyyy So based on it was trying to force the separators…
-
3
votes2
answers54
viewsWhat does the # operator do before a parameter in the definition of a macro?
One of the possible macro definitions assert(), as I found in Mingw’s code,. #define assert(_Expression) \ (void) \ ((!!(_Expression)) || \ (_assert(#_Expression,__FILE__,__LINE__),0)) I don’t…
-
3
votes4
answers744
viewsHow to get the highest and lowest number among 15 typed numbers? C++
An algorithm that reads 15 real numbers, and writes the largest and the smallest among the numbers read. I’m not getting to do the part of writing the smallest and largest of the numbers typed.…
-
3
votes1
answer607
viewsDoubt with Random in c++14 and 17
I was searching the Internet for how to do pseudo-random numbers in c++ and all the examples I found were with the srand function, but in some places people said srand is from c, and c++ already has…
-
3
votes1
answer51
viewsWhat is the difference between the pre-processor directive and the if statement?
In what situation should I use the directive #if? And the reserved word if?
-
3
votes1
answer1067
viewsHow to Calculate CRC Modbus RTU
I’m trying to calculate a crc Modbus in an application for PIC, but the returned crc is always incorrect compared to online simulators. follows the code void CRC (unsigned char* msg, unsigned char*…
-
3
votes2
answers60
views -
3
votes1
answer62
viewsDifference of {} and = in a declaration
What is the difference of two statements? On what occasions should I use each one? - int Num{15}; - int Num = 15;
-
3
votes1
answer58
viewsIs it recommended to use typedef in C++?
I know C++ is compatible with C, but C++ has its own way of programming and C as well, so there are legacy things from C that shouldn’t be used in C++, the typedef is one of them? If yes, what to…
-
3
votes2
answers84
viewsHow to return the last character of a String in C++?
I want to make a program that shows on the screen the last character of a String. In Python it would be something like this: nome = "Teste" print(nome[-1]) Upshot: and So I tried to adapt it to C++:…
-
3
votes1
answer36
viewsIf the class ofstream is to write to files, ifstream to read and fstream to both cases, why not always use fstream at once?
Even if we wanted to read, write, modify, create, delete files, or other operations, we could no longer use the class fstream? What problems could they generate if you don’t use those specific?…
-
3
votes1
answer89
viewsArray bug when passing size 4
I’m asking a question that asks the following: So I made this algorithm: #include <stdio.h> #include <stdlib.h> int main() { int i, j, x=0; int vetor[x]; printf ("Digite o tamanho do…
-
3
votes1
answer68
viewsError in Lexing a Mathematical Equation
I’m doing a C++ equation interpreter and I’m trying to show the type of the symbol. But I’m in trouble. I don’t know what’s wrong. Any constructive tips are welcome. main.cpp: #include…
-
3
votes1
answer113
viewsHow to set a pointer as the default parameter in C++?
I am "programming in C", but compiling using the extension .cpp and the g++ to have some facilities. My goal is to make a program that receives a starting salary and calculates the final salary…
-
3
votes2
answers122
viewsWhat is it for { } inside the main
I came across a situation in C that I do not know and had never seen anyone use before. Within the method main() there are several keys, I believe that to isolate the code but there is a same…
-
3
votes1
answer557
viewsCount how many columns are in a C++ CSV file
I am doing a design of an electronic ballot box, and for that I need to read a csv file where there is information about each candidate. As this csv file has a lot of information that is not…
-
3
votes0
answers470
viewsMonte Carlo methods in C++
This is the code I created to calculate in C++ using the Monte Carlo methods, the average distance between the points evenly distributed in a cube. I don’t understand why in the output file…
-
3
votes1
answer80
viewsQuestions about "linkage"
I tried to pass to IDE a code I found in a book and some doubts arose. Code: newApplication.cpp #include "stdafx.h" #include <iostream> using std::cout; using std::endl; #include "GradeBook.h"…
-
3
votes2
answers59
viewsHow to instantiate objects in shared memory?
I have an application in which there are several parallelization modes. However, when I will parallelize through Fork() the barrier is not shared between processes, there is some difference of the…
-
3
votes1
answer56
viewsQuestion about address in the pointer mémoria
I put a Cout in the way insertRight to verify the memory addresses of node1 (of the variable itself and not of what she keeps) and to my surprise the addresses shown repeated several times, as shown…
-
3
votes1
answer198
viewsHow to Suspend a Process-Specific Thread (.exe) in C++?
I want to suspend a specific thread from a C++ process by Startaddress. My code already suspends some threads of the process, but others do not... It seems that this only happens to address that…
-
3
votes2
answers372
viewsQt - Check if table is empty in the database
I have an application with a database connection, when initializing the application I need to check if there is any record in the table, if a user should not be registered, when I run the query…
-
3
votes1
answer118
viewsCompiling an inherited class in C++ gives constructor error
I need to create a class for chess pieces. I created the class Peca and her derivative, Bispo. When I try to compile the bishop class, the compiler returns reset error. How can I resolve? #ifndef…
-
3
votes1
answer273
viewsHow to assign a character to a string position?
I’m having some difficulty assigning a character to a certain position of string. I researched a lot before asking here and found nothing. Criticism is always welcome. This function is a part of a…
-
3
votes1
answer64
viewsTime to send data
I’m developing a small meteorological station to apply on a farmland, which is to have a temperature sensor, a rain sensor and a humidity sensor to be uncooked later because I don’t have it yet.…
-
3
votes2
answers218
viewsDestructor in C++
In solving some issues in C++, I came across the code: class MinhaClasse{ private: int a; public: MinhaClasse(int b){ a = b; ImprimeA(); }; ~MinhaClasse(){ IncrementaA(); ImprimeA(); }; void…
c++asked 5 years, 4 months ago Luiz Augusto 2,482 -
3
votes1
answer73
viewsIdentify accented letters and print a warning
I need to make a program that accepts only letters without accent, and for that I’m trying to do something that identifies a letter with accent and then print a warning about the error, but when I…
-
3
votes2
answers95
viewsHow to print a class in c++?
Good afternoon, what am I doing wrong in printing the Team class (name, number of members) in the penultimate line of the code? Shows the error: Invalid operands to Binary Expression…
c++asked 4 years, 2 months ago Maria Fernanda Pedrosa 39 -
3
votes1
answer31
viewsClasses with Static attributes and methods that create themselves
Hello, today at the company I work saw a different way to create an object, I asked why? And I was told that the company’s standard is not to use static objects, I found it interesting. I tried to…
-
3
votes3
answers81
viewsIs it possible to use functions in an arbitrary order in C++?
Apparently, the order in which functions are written matters in C++. Example, this code compiles: #include <iostream> using namespace std; int add_number(int x, int y){ return x+y; } int…