Category "c++"

Is bitwise complement of (n-1) equals to (-n)

The following code prints the two odd occuring numbers in an array: #include <iostream> using namespace std; int main(){ int n; cin>>n; int

Linear Probing - Collision Troubleshooting when Inserting Element

I'm trying to create a Linear Probing program. So far, I'm stuck trying to create an insertElement function. The idea is that as key values are being inserted i

Printing a matrix in spiral order but getting an additional element

#include<bits/stdc++.h> using namespace std; // Printing a matrix in spiral Order int main() { int n, m; cin>>n>>m; int arr[n][

Passing an array in struct initialization

I would like to create a struct which contains both an int and an array of int. So I define it like struct my_struct { int N ; int arr[30] ; int arr[30][30] ; }

emplace and try_emplace with copy constructor

I have an issue with emplace and try_emplace as they always use the copy constructors when moving an object in. #include <iostream> #include <unordered

SDL2 make pixel array into texture

I trying to render a special image which is just a bunch of pixels with no format. It is a sort of a raw image with 42x 42 pixels. The images are palettes so I

Add a button with functionality in c++ using Visual Studio

I am a newbie to c++ and the IDE I am using is Visual Studio '22. I have written a code to detect a face (eyes and mouth too) and save the roi to a folder on th

Defining an atomic<> as a static variable inside a function

C++11 mandates that static variables inside a function are atomically initialized for the first run of the function. The only way to do that efficiently is doub

c++ build error, redefinition of static variable, undefined element

I writing application using c++ and Qt. I have a problem with building application. I get many error but everything refers to static variable and undefined func

Recomended formating for temporarily inverting data at pointer and then passing pointer to temporarily inverted data

Long story short, I have a pointer to a value that is stored inverted, so when we are calculating a hash to verify data integrety, we need to invert the data th

Sorting vector of blocks C++ SFML

I just wanted to make a little program to sort blocks using selection sort, but it doesn't sort itself. Blocks just keep switching places in some pattern, until

Tiff Windows Imaging Component c++

I am trying to replace libtiff into WIC (since libtiff is not able to pass Black Duck Analysis tool anymore) I have used their example https://docs.microsoft.co

Two sinks logger as default logger not working

I'm trying to combine two sinks: auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>(); console_sink->set_level(spdlog::l

push_back element to vector in class object isn't working

classObject and vector within it. I made a vector of classObject and function that searches classObject with a given int id. Wanted to search certain classObjec

Visual studio 2019 Google test nuget package restore failing

I have this error when I try to open some students' assignments in Visual Studio 2019, stating that nuget can't restore a package. I'm concerned about the direc

How to get the value of a template class?

I'm trying to get the value of a template class. To get the value of a class, I can easily do like: int get_value() { return *this; } But I want to create

How to address the "Lock was destructed while held" Visual C++ runtime assertion

In a program that uses DirectX to render a 3D component I use a dedicated rendering thread that apparently gets created if I call DispatcherQueueController::Cre

Problem creating dll and loading then in Python ctypes

I want to learn to create DLLs in c++ and use them in python to increase the speed of calculations. To begin with, I tried to create a simple C++ dll and load

Difference between !(n & 1) and n & 1 == 0 in C++

For some reason in C++, the expressions if(!(n & 1)) and if(n & 1 == 0) seem to not be equivalent. Can someone please explain why this happens?

If there is a difference between two constructs

If there is a difference between two constructs I would like to know std::string name = std::string("Eugene"); and std::string name = "Eugene";