## How to find the Largest sorted sub matrix (sorted row-wise as well as column-wise) of a given matrix?

Given a matrix of order n*n. I need to find the length of the largest sorted sub-matrix (sorted both in row-wise and column-wise manner in increasing order). I made the following code which is not giving out the correct output because of some error i...
more »

## Create std::vector in-place from raw data

Given a raw array of elements, how to create a std::vector that takes ownership of the raw array without reallocate & copy? For example having the raw array: int* elems = new int[33] how to create a std::vector of size 33 pointing to elems? I...
more »

## What does it mean to compare pointers using relational operators?

If I have two pointer variables, a and b, what does it mean to to use the statement "a < b"? Is doing so supposed to compare the values of their memory addresses? If so, what would be the order of memory addresses in the computer? ...
more »

## Get path of Java application that launched the executable

I am trying to validate that only our Java application has launched an inside-included executable. To achieve this, I thought of having a list of valid known SHA2 hashes (of the Java application) on our server and the executable will first check if t...
more »

## C++ short array 'reversed' when casted to integer

As a newbie in C++ I've been playing around with pointers a bit. I have written the following code to interpret a short array as an integer: #include <iostream> int main(){ short array[2] = {10, 9}; short* pointer = array; std::co...
more »

## Why offsetof implementations strangely differs on C and C++?

I opened stddef.h and saw this: #if defined _MSC_VER && !defined _CRT_USE_BUILTIN_OFFSETOF #ifdef __cplusplus #define offsetof(s,m) ((size_t)&reinterpret_cast<char const volatile&>((((s*)0)->m))) #else ...
more »

## Binary Search - Output is not displaying after code compiles and runs

I'm just now learning about binary search in class and the code below is simply an example because I'm trying to understand it better. So with that said this code is compiling but not displaying any output and because of my lack of knowledge of Binar...
more »

## read number occurrence from file with no delimiter c++

I have a working prototype with the code being read from the file. My problem is figuring out how to read it from the file without any spaces. For my code below to work properly, the file's contents needs to look like this: 3 4 6 2 5 What I'm lookin...
more »

## compile order eclipse c++

I am trying Unit test using Gtest. I am creating a another project that has file from the original project (By linking) that is to be tested. In the new project I then create Fake Implementation and Mocks of the additional dependencies of the functi...
more »

## Shifting Objects Up in an Array

I'm creating a program that creates an array of objects in random positions in an array size 8. Once created, I need them to sort so that all the objects in the array are shifted up to the top, so no gaps exist between them. I'm almost there, but I c...
more »

## Can POSIX timers safely modify C++ STL objects?

I'm attempting to write a C++ "wrapper" for the POSIX timer system on Linux, so that my C++ program can set timeouts for things (such as waiting for a message to arrive over the network) using the system clock, without dealing with POSIX's ugly C int...
more »

## Using STL algorithm to find all matches in a set

I have a set containing Song objects. I want to search for all occurrences of a Songs that have a particular title. I am required to use a STL algorithm. The problem is when it finds the first occurrence it stops searching. I am trying to fix it by...
more »

## C++ find_if member variable of another class

So I have a class called Song, and another class Called SongLibrary. The Songlibrary just contains a set of all songs and appropriate methods. I am currently trying to make a function to search the song library and check if a song has a particular t...
more »

## Is a log(n) std::find_if possible?

I will define a class and use a container (possibly std::set) with a custom comparator function (basically, raw integer comparison on a class member variable). I wish to know if I can somehow keep this set std::sorted and use std::find_if with logari...
more »

## How does the standard define the capture of runtime-bound array?

Please consider this code: #include <iostream> #include <algorithm> #include <numeric> int main() { volatile auto width = uint64_t(5); alignas(16) char runtime[width]; std::iota(runtime,runtime+width,'1'); auto o...
more »

## C2678 binary '==': no operator found which takes a left-hand operand of type 'Contact' (or there is no acceptable conversion)?

I am having trouble getting the right operator== overload function to make this 'find' algorithm to work. What I am doing is passing an object 'Contact' into a parameter for another object AddressBook using its member function to remove an object fou...
more »

## Does std::array of std::array have contiguous memory?

Seems, that I found how to easily get normal 2D Array with contiguous memory in 2 lines of code: template<int N, int M> using Array2D = array<array<int, M>, N>; Let's solve easy task of swapping min and max in Array2D (a little o...
more »

## What will be enough for uint64 16000000000000000000?

What will be enough for uint64 16000000000000000000 ? ((uint64_t)16000000000000000000U) or ((uint64_t)16000000000000000000UL) or ((uint64_t)16000000000000000000ULL) ? ...
more »

## How to sand box C/C++ projects which use shared libraries

I sometimes dip my toes to Free C/C++ projects that I would like to experiment with. Nine times out ten this results in a lot of pain to get all the dependencies to work and crucially inevitably this breaks some other project's dependencies so that ...
more »

## how to make 2 = .01 and .01 = 2?

Okay so the title may not make the most sense but I will explain it better here.. what i'm trying to do is take the value of 2 and make it equal to .01 and make .01 = 2, well I tried to hardcode it like this if (Value = 2) Value = 0; else if (V...
more »

## deleting array from heap

My question is about deleting an array from heap memory. I read a book and this blog and other resources like this one, and all of them said that for deleting an array from heap we must use the [] after the delete function so if we write our codes w...
more »

## In a structure, is it legal to use one array field to access another one?

As an example, consider the following structure: struct S { int a[4]; int b[4]; } s; Would it be legal to write s.a[6] and expect it to be equal to s.b[2]? Personally, I feel that it must be UB in C++, whereas I'm not sure about C. However, I ...
more »

## Can a compiler read twice from a global variable, instead of storing a local one?

I've been trying to get re-familiarized multi-threading recently and found this paper. One of the examples says to be careful when using code like this: int my_counter = counter; // Read global int (* my_func) (int); if (my_counter > my_old_co...
more »

## Using send() to send values as part of string over TCP/IP stream socket

I've been writing a client/server model. Throughout my program I've been writing stuff to the socket like: write(sock,"Please enter your password.",255); I have an integer on the server side, GBPbal. I want to be able to send GBPbal as part of the...
more »

## C++: how to assign static array to a pointer inside a struct

I have C-code that I need to compile to C++ and need to minimally change it. In C, the following works typedef struct _type_t { int a; int b; int c[]; }type_t; type_t var = {1,2,{1,2,3}}; But in C++11, it gives the error error: ...
more »

## Rcpp isn't finding Boost headers

I have a file called src/windows.cpp (windowing functions for vectors, nothing to do with MS Windows!) in an R package project. The top of the file looks like this: // [[Rcpp::depends(BH)]] // [[Rcpp::plugins(cpp11)]] #include <Rcpp.h> #incl...
more »

## QML Qt- Parse XML and convert it as a LisView's ListModel

I'm new to Qt and QML. With that said, I am making a editable list in QML which I would like to import and export as XML file. Right now I'm stuck on importing it from XML file and setting it as my ListView's model from the C++ side. I'm hoping I ca...
more »

## Can I call a std::function from C?

I have some C++ code that returns a std::function. I would like to call this from some C code. Is this possible? As an example I have the following code: typedef std::function<int(int)> AdderFunction; AdderFunction makeAdder(int amount) { ...
more »

## "Error: incomplete type "unsigned char[]" " when compiling with SUN C++ on Solaris machine

I have a definition of unsigned char tmp[]; as a member of a structure. When compiling with g++4 on Linux RedHat it does not complain. But when compiling with Sun C++ on Solaris 5.10 machine I get an error: Error: In this declaration "tmp" is...
more »

## for - loop for group of elements in vector that references other vector

I am trying to find out why this piece of code returns -1. The fault lies within this piece of code, and I guess I am handling the iterators wrongly here. What I am trying to do is calculate a geometric mean. You can fault me for several things here ...
more »

It's my first question on stack overflow. So, I've got an Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT) error in my code. I think it's related to the do-while or just while cycles. Where did I get wrong? I want to make a converter to reverse ...
more »

## Eclipse-cdt - include files issue (resets after change)

I have a problem with eclipse-cdt (latest version). I dont use any toolchain here, just simple makefile. There is no problem with building - everything works but eclipse annoys me when i change something in my code. For example: some random code wh...
more »

## eclipse c++ cant find windows macros and functions in <window.h> for window application

I'm using eclipse cpp oxygen with MinGw compiler/toolchain. I've managed to make a window app in visual studio 2017 with the help of a wizard and I've seen some of things that are supposed to go into the program such as the macro "CALLBACK" but i ca...
more »

## How to manually create a boost ptree with different XML attributes?

I am using boost libraries to parse XML files and I have to create a ptree manually. I want to create below xml file using boost ptree. <?xml version="1.0"?> <Txn> <Resp errCode="0" errInfo="" /> <A exptime="20171230"&g...
more »