Newest 'c++' Questions

Q&A for professional and enthusiast programmers

How to cast a float to (char*) C++ and BitStream

I am trying to cast a float to (char*). The line of code I tried to write is: RakNet::BitStream bs; bs.Write((char*)m_position.x, sizeof(m_position.x)); Now, I am using BitStream from RakNet for ...

how to split a string into lines, without breaking the words?

Let's say we have a string we wish to split the string into 5 chars long without splitting individual words: I am going to CUET Now if we can split this in the following way: I am going to CUET I ...

c++ global variable was not declared in this scope

I am new to C++. I am trying to modify a very complex video codec code as part of my final year school project. This is my code: This is the header file in which I have declared three extern ...

Calling address of function from c++ from __asm [duplicate]

Basically I need this as simple as it can be done: __asm { call 0x401000 } Remarks: I know if i do it this way: __asm { mov eax, 0x401000 call eax } It will work as intended, but I want ...

Ownership of memory in user-defined classes deriving from Qt classes

I know that, in Qt, parent object takes ownership of its child objects. However, if I have my own class deriving from a Qt class, do I need to control memory in my derived-class' destructor or does Qt ...

Qt wait until a process is finish

I have a problem with a Qt application(QML) when i run a new external process. I have a button and on push he need to do something like this: void TerminalLauncher::open_terminal() { this->proc....

Is “std::is_callable” replaced with “std::is_invocable” in C++17?

cppref has removed the entry page for std::is_callable, and use std::is_invocable entry page instead. However, std::is_callable is still available in Visual Studio 2017. Is std::is_callable formally ...

Algorithm for moving links with priority to head of a list

I have to create a priority queue using a linked list. I first generate a queue with no priority (priority=0). My algorithm is as such for enqueueing: 1. Create a new Link, pointer for second link, ...

Header file or library to share constants?

I'm working with an LED library to make some blinking lights. I found working with numeric Color values irritating, so I created my own list of gamma corrected Color name values (about 160 of them) I'...

LAME library: How to set bitwidth from C++ code

There are many questions on LAME but I could not find what I'm looking for. I'm writing a C++ program that converts WAV files to MP3 and it seems to work but not for 24bits WAV files. I cannot find a ...

Why the mouse is moving on the lower right?

This is my code: #define WINVER 0x0500 #include <windows.h> void MouseMove (int x, int y ) { double fScreenWidth = ::GetSystemMetrics( SM_CXSCREEN )-1; double fScreenHeight = ::...

Cant Use my function that i 've created in Header file [on hold]

I'm trying to use my function that i've created previously in Main.cpp and then i came up with the idea to include my function to my own header file named center.h . i'm not sure why i cant called my ...

making array of alpha char with c++ cipher

i want to get word from user and put it at array [5][5] by sequence and then after adding this word adding alpha char with out the char of this word(Playfair cipher)

Set current user environment variable from c++ code visible to other process like cmds

I need to set a local environment variable for current user and it shoukd be visible to other processes like a new command prompt. I need it for windows. I have tried options like putenv and editing ...

Visual studio c++ header relative path with angled bracket

I am new to visual studio. I am trying to use Valijson The problem is the header file contains relative path to various header. but the compiler is complaining about the relative path. I looked into ...

Forward declaration of struct with constexpr constructor

I would like to add global instances of a struct class to my program that server special meaning. A MWE that works is // Example program #include <iostream> constexpr int x_max = 3; constexpr ...

Visual Studio does not show all my methods

I am writing a game and already have many thousands lines of code, many files, classes etc (watch http://hotar.de/ if you are interested). However if I open my main file which has over 25000 lines ...

Bigint arithmetic operation in linked list

I have two doubly linked list with the unknown length of nodes of numbers. I need to do add and multiply two lists. What is a good way of solving the problem ? I tried to do with operator overloading +...

C++/CLI function return with custom defined managed class type

I meet a problem when I'm using C++/CLI. I defined a class called Person, it's a simple class with gets and sets: #pragma once using namespace System; namespace CLI { public ref class ...

GCC extensions download from internet?

Is there a way to download to code blocks some extensions like #include_next? I am using code blocks 16.08, mingw, windows 10 for c++.

Finding minimum and maximum in a array c++

I have to find the minimum and maximum value of elements in a array using divide and conquer. I have written a code but it is not working for more then 6 elements in array. I don't know whats the ...

why SDL_RWFromFile( file ,“w+”) does not read and write like its supposed to? it only opens file for writing

can someone explain to me why this code won't work as expected. It seems SDL_RWFromFile using the w+ mode only works for writing and Not READING AND WRITING as its supposed to... what am i doing ...

Reading ASCII text file using an std::ifstream in C++

I have an Arabic file (ASCII), which contains: 121101 الزبون كمال 121102 الزبون سعيد 121103 الزبون عمار I want to read this file using an std::ifstream in C++ as: std::ifstream ifs(file....

User defined compare function in std::set in C++ [duplicate]

I am trying to use a user defined function in the set by the following code. But its giving error: expected a type, found 'comp'. What is the right way to do this? bool comp(int a,int b) { ...

Clear vector of vectors effectively C++

I came across having the need to create 2 or 3-level nested vectors but I had this issue of memory not clearing correctly. So I made this simple test: void test(){ vector<vector<double>> ...

What exactly does C++17 change regarding parallelism? (And where is the authoritative doc?)

Is parallelism as such a part of the C++17 changes? When I Google "c++ parallelism" (without quotes), I come across a few different docs, and I can't piece together the timeline or the definitive ...

FPS Timer Not Working

I'm creating a game in Visual studio 2015 with c++ and sdl-2, I'm currently implementing an fps timer but it's not working. The basic FPS Timer code: #include <SDL.h> #include <Camera.h> ...

Bind on C++/CLI delegate in Javascript (WinJS)

I am building a Cordova application for all major operating systems (iOS, macOS, Android and Windows). I wrote a native Plugin (WinRT) in C++/CLI to call some native functions, this Plugin uses ...

matlab to c++ conversion

So i have this matlab code and i'm trying to convert it in c++. The problem is that i don't know to much about matlab. Can someone explain some things to me. This is my code function [L,D]=ldlt(A) % %...

C++ SQL, How to check the insert/update/delete statement success

Connection *con = getSQLConnection(); PreparedStatement *pstmt; ResultSet *res; pstmt = con->prepareStatement("INSERT INTO `user` (`LoginID`, `Password`, `Name`, `Email`) VALUES (?,'password','...

android NDK(CMakeLists.txt) with c++11

Hi I'm making a face landmark detection app in ANDROID VERSION. I'm using Android Studio 2.3(NDK SUPPORT) So far so good except build.gradle & CMakeLists.txt setting CMakeList.txt set(...

How to define a class that can save variadic template arguments?

template<typename... Args> struct A { Args&... args_; // // error : only function and template parameters can be parameter packs // A(Args&... args) : args_(args) ...

How do I sort objects of a class type alphabetically? (C++) [duplicate]

My task is to sort the movies in main alphabetically. I have tried to implement a bubble sort, but I can not figure out how to get them to sort alphabetically. The movies are of class type "Movie" and ...

Incorrect number of integers being counted from filestream

My function is supposed to save integers into an array read from a JSON array in a text file. The len is calculated correctly for small arrays, but for larger lengths it is miscalculated. The JSON ...

How can I get the ROWID after an insert into an SQLite table? [duplicate]

How can I get the ROWID after an insert into an SQLite table, or the last inserted table row ID?

How to recompile the binary data into ASCII format? [on hold]

How can I recompile the binary data into ASCII format on my 64-bit machine and the OS is windows.Thanks a lot . More details:I am using cifar-10 datasets to learn CNN in images classification.My host ...

C++ does not allow vector with negative index?

I was trying to create some vector with negative index but just learnt that it was not allowed in C++. Is there any alternative or better way to do it? for example I want to create a 3D vector named ...

c++ - Putting values (and solving for its sum) in an array

I have this code and its job is to ask the user if how many elements they would like to enter in the array - the user then enters their desired elements - the elements are integers -then the program ...

Array values not printing correctly

I wrote this code for printing the productions after eliminating left recursion.And also i stored these output productions in "all" array. when i print this array, only the last values are being ...

Adding a left const to an array of pointers

I work with multiple arrays at a time. There are functions which need to change the arrays, others only need to read. Take for instance these functions: // Only needs to read from the two arrays. ...

why this implementation of a Gauss Legendre algorithm in c++ is not producing result?

I am learning c++ and I have found Gauss-Legendre Algorithm on wikipedia to approximate pi(link: https://en.wikipedia.org/wiki/Gauss%E2%80%93Legendre_algorithm). I tried to implement it with c++ but ...

How can I make a stepper motor run until I press a specific keypad button on Arduino?

Here is my code: #include <LiquidCrystal.h> #include <Stepper.h> #include <Key.h> #include <Keypad.h> const int stepsPerRevolution = 200; const byte ROWS = 4; //four rows ...

writing a map of structures to xml using boost

i could successfully write a map < string, struct values > to xml file using boost serialization but while i tried writing a map < int , map < string, struct values > > to xml file ...

OpenGL Mesh wont draw

I must be overlooking something painfully simple, though I'm unsure as to what it is. This code is comparable to other variants i have written before that have worked just fine. But for some reason, I ...

Reusable barrier Little Book Of Semaphore

I tried to implement the reusable barrier from Little Book Of Semaphore in C++. The problem: I want to run 5 threads. The barrier should block 1-5 threads. With my code, only one threads run through ...

How can you add to a QStringList being operated on by QtConcurrent::map?

I'm trying to create an application that will perpetually monitor a folder, and add any new files to a queue for multi-threaded processing. This is what I have: int main(int argc, char *argv[]) { ...

Coordinate iterator of point

How can I get a coordinate iterator of a Point p where Point is fulfilling the Point Concept?

C++ How To Show Percentage Output Of Dice Simulator Results

newbie here to C++. I am having trouble displaying the correct format + results in percentage form for this dice simulator our professor has asked us to make. I'll copy/paste her instructions here and ...

Generate N evenly spaced values between A and B (C++)

I need to generate 1000 evenly spaced values between -2 and 2 (similar to what numpy.arrange does in Python) in C++. How would I go about solving this? I have tried the following: for (int y = 0; y &...

Locking registers/ coding registers in C or C++

I was thinking about the classes I've taken none of them talk about using c code to write directly to the register. I want to be able to do things like lock a register and etc like a thread. Of course ...
Translating... 0%