Click here to Skip to main content
15,891,431 members
Everything / Programming Languages / C++11

C++11

C++11

Great Reads

by Shao Voon Wong
Floating Point Format For C++ and C# Programmers
by Michael Chourdakis
An easy locking class for shared/exclusive mutex functions with upgrade/downgrade
by MehreenTahir
This article will show you an alternative way of using C++; How to write functional code in C++. You’ll see how to write more concise, safer, readable, reasonable code.
by Shmuel Zang
This article shows how we can implement a thread-safe events (similar to .NET events) mechanism using the standard C++ library.

Latest Articles

by PJ Arends
An MFC CWnd derived grid of user definable tiles
by Shao Voon Wong
Bring your animations to H264/HEVC video using C++ and C# with h/w acceleration
by Piotr Grygorczuk
Enable C++11 multithreading features in GCC for FreeRTOS
by Shao Voon Wong
H264/HEVC Video Encoder for recording OpenGL rendering

All Articles

Sort by Title

C++11 

15 Oct 2012 by Cpp For All
finally like clause in C++
4 Jan 2018 by john morrison leon
Class method emulation for plain arrays plus unified handling of plain arrays, std::arrays and std::vectors
25 Jul 2014 by Nish Nishant
The article goes through sevean language and IDE features in the VS 14 CTP 2 that are specific to C++ development
31 Oct 2015 by Stefano Lodico
I'm sorry for my bad English, but it isn't my language.I've done an exercise in C++11 for University (Goos Game):this is the code (3 files):header.h#ifndef C#define Cclass Campo{ public: Campo(){ turno=0; g = new...
10 Apr 2018 by Member 13770638
In fact my coursework requires me to create a simple sudoku game using Qt creator but the learning curve is killing me. I am thankful for what others have created for our ease of use but often times I would rather prefer to understand low level stuff first (perhaps down to transistor level) like...
10 Apr 2018 by KarstenK
Qt isnt so hard to learn, so read some of the Qt tutorials. When you Google you may finde some sodoku examples.
10 Apr 2018 by CPallini
Since Qt is required, you have to, at least, use it in your application. Modify an existing example in order to fit your needs and don't bother to really understand it. If you ar really interested on what there is under the hood, then have a look at Walkthrough: Creating Windows Desktop...
6 Aug 2020 by JacksonSteel
input: babad abbd output: ad bb expected: bab bb #include using namespace std; class Solution { public: string longestPalindrome(string s) { int maxlength=1; bool ispalindromic[1000][1000]={false}; ...
4 Aug 2020 by OriginalGriff
Compiling does not mean your code is right! :laugh: Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email...
6 Aug 2020 by Patrice T
Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes. #include using namespace std; class Solution { public: string...
4 Oct 2011 by anktrive
Hi, I am new to JNI and I have been trying to write a simple program to call Java code from C++. I am facing problem in creating the JavaVM from C and am getting the Linker error. I have tried changing the GNU library files in dev C++ (I am using Dev c++ compiler) but no luck so far....
3 Oct 2011 by Richard MacCutchan
See here[^] to check your code is following the correct rules. Also, make sure you have defined your JNI calls within extern "C" {} blocks, to prevent name mangling by the compiler.
4 Oct 2011 by Richard MacCutchan
I don't know why this happens BUT:In your C code, if you replace the line:res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);with// this should contain the path to the JVM DLL fileHINSTANCE hVM = LoadLibrary("C:\\Program Files (x86)\\Java\\jre6\\bin\\client\\jvm.dll");if (hVM...
5 Oct 2011 by Espen Harlinn
It's customary to locate the java runtime trough settings from the registry, and then load the dll dynamically.Have look at:Jace[^]Jace offers some additional features you might find interesting too.[Update]The _imp__ prefix indicates that you have a problem with your library - I...
5 Oct 2011 by Richard MacCutchan
My apologies but I was compiling as C++, which does not work for standard C. Modify the code between the lines #ifdef JNI_VERSION_1_2 and #else as follows:#ifdef JNI_VERSION_1_2// definitions required to get the proc address HINSTANCE hVM; typedef jint (CALLBACK *fpCJV)(JavaVM**,...
22 May 2022 by Phoenix Liveon
�����Is there a way to have this initialization block similar to Java that we could implement and run properly in C++. There were two types of init-block in Java: 1. init-block/raw-init-block, this will invoke at every new instance created. 2....
31 Dec 2021 by Richard MacCutchan
You could probably simplify that by the use of the singleton pattern - Google Search[^].
5 Jan 2022 by Phoenix Liveon
What I did for now was to call/invoked it inside of the first line of one of any constructor, Note: upon by doing it we need to have a delegated constructor if we do had multiple overloaded constructors, so that we could link it together, then...
5 Jan 2022 by Stefan_Lang
You seem to try and imprint another languages' properties onto C++, and that is never a good idea! My experience with java is limited, and I'm not sure what you actually have in mind, but the code you posted is clearly not the recommended way of...
31 Jul 2014 by Michael Gazonda
A Fundamental Lock-Free Building Block - The Lock-Free Stack
28 Jun 2016 by JohnX2015
This is a cross-platform general C++ engine, including a general runtime and a reflection engine.
16 Dec 2015 by Tim ONeil
INI-style properties for C++ Embedded/Applications on Linux
28 Jul 2017 by Irdia_36
I do not understand the issue is in my code, I have not seen an error like this so I don't know where to start to debug it. I have only been learning to write code in C++ for about a month now. So, the issue is this "No suitable conversion function from const std::string to char exist." in this...
27 Jul 2017 by Jochen Arndt
As already suggested you should show the declaration of the tpyes. However, from the error message something like this can be assumed: std::string HorseNames[MAX_HORSES]; struct { char name; // Probably more members here } Horses; Horses horses[MAX_HORSES]; Then HorseNames[i] is a...
28 Jul 2017 by Richard MacCutchan
You cannot store a string in a char variable; a char type can hold only a single character. You need either a pointer to a string (char*), or a character array (char[]) as Jochen has suggested above.
15 Mar 2016 by Satbir S
A worker thread gives you parallel processing power
16 Mar 2022 by honey the codewitch
Get your data on, even on platforms without a reliable STL implementation using these simple but critical classes.
9 Apr 2018 by Member 13770287
Suppose we have 3 arrays: One for the players' names,one for the games' names, and one for the games' scores.The size of the arrays is defined by the user. we're supposed to use a function to add players' scores in a game and then display the names next to their correspondent score ,How can we...
9 Apr 2018 by Rick York
The first problem is this sequence of code : void pscore(char pname[]) { int pcounter; int gscore[pcounter]; ... } That will not compile because the array size needs to be a constant expression. If the count is going to be a variable expression (entered by the user) then you should...
9 Apr 2018 by OriginalGriff
I indented your code: nobody cares which indentation system you use: K&R, Whitesmiths, even the execrable 1TB is fine as long as you are consistent. Now look at your code, and assume that the user enters "2" as the number of games. How big is pname as a result? char gname[p],pname[p]; Answer:...
9 Apr 2018 by KarstenK
Your idea misses of a good design. In your tasks the player are a class with members for the name and the score. And a class for games with a player and a name score. When you use standard library classes it gets more easier. Use std::string and std::vector for an easy control flow. Include the...
12 Jun 2019 by John Bandela
The problem brought to light by the article is that C++11 auto interacts badly with expression templates and proxies.
25 Feb 2019 by Member 14158970
I want to segment an Image(basically text/doc Image) into header footer body and in body extracting paragraph.Image is in binary form i.e m*n matrix element contain only 0 and 1 0-for black pixel i.e text and 1-for white pixel no text I am thinking like this I start from top for header...
21 Feb 2019 by Richard MacCutchan
You need to start by getting the dimensions of the page and calculating the height and width of each section that you will print into. Then within each page section you calculate the size of a paragraph, column, margin etc. Try drawing the boxes on a real piece of A4 and then see what you need...
23 Mar 2019 by Member 14192637
I'm new on this forum. I'd like to ask you a question that has been annoying me all this day. the problem is that i don't find anything on internet about it. At the university we have to do this: Write a program that: -Loads the checkerboard images. ( these imagines are in a folder provided by...
22 Mar 2019 by Rick York
The problem is in the for loops. You stated there are fifteen images. Since array indexes start with zero, the fifteenth image will be index fourteen but your for loop goes out to fifteen. A better way to do this would be to define a constant : const int ImageCount = 15; // and write...
22 Mar 2019 by Member 14192637
Hi. First of all, thank you for answering. I followed your valuable advice(with a little modification, but that's the point), but the problem doesn't change. here the piece of the code correct: for(int i = 0 ; i
26 Apr 2020 by Member 14771149
I want to make a class superhero which contain a protected data member health and member function: 1- non default constructor that initialize health if entered >100 to 100 2-Apply power function which takes a pointer of super hero class P and...
26 Apr 2020 by Daniele Rota Nodari
superfighter is a subclass of SuperHero. ApplyPower receives a SuperHero instance through parameter p. You want it to change p->Health but instead you are changing Health value of the superfigther instance. "SuperHero::Health -= firepower" is not...
26 Apr 2020 by Stefan_Lang
A word about inheritance: When one class inherits from a base class (also called super class), it means that it inherits all the properties and functions of that base class. An instance of that derived class is still only one instance though!...
9 Nov 2018 by gtyoung2
class Student { public: //Accessor int fetchAge(); int *fetchDaysInCourse(); string fetchEmail(); string fetchFirstName(); string fetchLastName(); string fetchStudentId(); Degree fetchDegreeType(); //Mutators void mutateAge(int); void mutateDaysInCourse(int[1]); void...
9 Nov 2018 by KarstenK
You need to use the debugger for solving that problem. Typical for your last problem is that the Student object is invalid like a null pointer or deallocated memory. Set a break point some calls before that crash.
8 Nov 2018 by mhaque1
I am using QuickBooks SDK 13. I am trying to make entries in bank transactions in c#. I need to know which Request to use for this. Can anybody please help? What I have tried: I tried many request messages, but none worked.
8 Nov 2018 by Dave Kreskowiak
You're asking the question at the wrong site. Ask this in the Developer forums[^] at Intuit. There you're going to find everyone who uses the Quickbooks SDK and a lot more experience with it.
8 Jan 2018 by CodeBlooded
So, I what I want is to collect maximum element from each row(in a 2D vector) and push it into a new vector. And if the new vector is sorted I want the sum of all vector elements. I tried it but the code is showing error : "cannot convert 'std::vector to 'int' assignment" also, is my code...
8 Jan 2018 by Patrice T
You try to solve this problem Contest Page | CodeChef[^]. As usual CodeChef challenges are not for beginners, and unfortunately you have read the requirements too fast and misunderstood it. All details count. Someone else have asked for help, read answers given, they should help you to...
27 Jul 2015 by Manuele Finocchiaro
Reflection for C++ made easy
6 May 2020 by Arthur V. Ratz
In this article, I’d like to introduce the modern code in C++11, implementing the parallel three-way quicksort, which is asymptotically faster and more efficient than the famous heapsort and mergesort algorithms.
16 Jan 2013 by Ajay Vijayvargiya
Covering the nitty-gritties of C++ templates.
16 Jun 2019 by Michael Chourdakis
Create dynamic multidimensional arrays in place
29 May 2021 by Member 15078716
I have read about using buffers to move a ball on the screen. I am using C++11 on Microsoft Windows 32 bit. No visual C++. No Visual Basic. No .NET. No Active X. Please. Thank you. Would you please look at what I have and adjust it to correct...
19 Aug 2019 by VISWESWARAN1998
An opensource antivirus engine which uses Yara, Locality Sensitive Hashing to detect malware
7 Mar 2019 by Member 11520335
Any example for 3 Months Validity of password in c++. Am able to check strength of the password What I have tried: New to password management system. Dont know how to validate.
6 Mar 2019 by OriginalGriff
What you need to do is store an "expiry date" in your DB along with the password. When the user signs or changes his password up you set it to the current date plus the validity period - 3 months in this case. When the user logs in, you check the expiry date, and behave appropriately. But ......
7 Mar 2019 by KarstenK
Storing a password is a bit of an art, you should use some "salt" and "pepper" and only store some SHA-2 or better hash. So it would better to store only an expiration day with the user name in some database.
31 Aug 2012 by Mikhail Semenov
keywords: user-defined literals , templates, constant expressions, recursive functions
13 Aug 2015 by Joren Heit
Easy, compile-time manager of EEPROM variables
13 Aug 2015 by Joren Heit
Easy, compile-time manager of EEPROM variables
9 Oct 2015 by Member 12047139
Assuming that there is a functional program built around this will the following work:Item** items;Item* item;int nItems;items[nItems] = item;Or would I have to set each member variable of each instance of Item more like this:int newId =...
9 Oct 2015 by George Jonsson
The first option will work with some modifications, provided that the variables are initialized properly.int nItems = 5;Item** items = (Item**)calloc(nItems, sizeof(Item*));Item* item = new Item(); // If Item is a classitems[nItems] = item; // nItems will be outside the length of...
9 Feb 2019 by Kohila G
Find the smallest window in a string containing all characters of another string - GeeksforGeeks[^] I can't wrap my head around this code. What does array inside an array mean? How can a character be an index to an array? What I have tried: // C++ program to find smallest window containing ...
9 Feb 2019 by Rick York
You have to think about what data each layer provides. The variable str, a string, is an array of characters. A character is just an integer of one byte. That means the value of str[j] is an integer that could range from 0 to 255, the range of one byte. That value is used to index into the...
9 Feb 2019 by Patrice T
Quote: How can a character be an index to an array? Learn about ASCII coding. Your don't understand what this code is doing, a tool can help you to, it the debugger ! Run your code on debugger step by step, inspect variables. The debugger is here to show you what your code is doing and your...
1 Nov 2013 by Gabi Barcan
Call methods of an existing class in MFC asynchronously, while still preserving the thread affinity required by MFC and COM.
20 Nov 2018 by fisadmaster
I have a console application in C++ that when loaded load a library in C#, which, in turn, when loaded shows a modal form with several buttons. I need to implement a call back function from C# to C++ to indicate, in the C++ console output, every time an action is made in the modal form. When...
16 Nov 2018 by TheGreatAndPowerfulOz
Is there a reason the console has to be in C++? Is this a dumbed-down example so you can get this working in another, more complicated context, like a legacy C++ app or COM object? If not, then ... 1) Why not use C++/CLI which is also managed code? or 2) You can write a console app in C#. So...
18 Nov 2018 by User 11060979
I did similar things before some years. A very pragmatic Approach (and maybe also a very dirty one). Keep in mind I noted here what I remember... The c# part public class CSharpCom { // c++ Callback stuff private delegate void CPPCallBack([MarshalAs(UnmanagedType.BStr)] string text); ...
3 Jan 2016 by Member 10870731
i have got weird result when i executed this for-loop with auto keyword. could someone explain why i got weird result in this for-loop?#include int main(){ for (auto i = 0u; i = 0u; --i) // ??????...
3 Jan 2016 by Richard MacCutchan
You are declaring your values as unsigned so when i goes from 0 to -1 it is treated as the unsigned value 0xFFFFFFFF, and the loop goes on forever. If you change the second loop statement tofor (auto i = 2u; i > 0u; --i)// orfor (auto i = 2u; i != 0xFFFFFFFFu; --i)// or better for...
13 Feb 2020 by Visweswaran N
In this research, we are going to prove that Import Address Table is very helpful in classifying a malware.
27 Dec 2017 by Petrov Vladimir
Simple solution for small avi demo performance from Image files of any kind
13 Aug 2020 by Member 13898042
There are two banks – Bank A and Bank B. Their interest rates vary. You have received offers from both banks in terms of the annual rate of interest, tenure, and variations of the rate of interest over the entire tenure.You have to choose the...
13 Aug 2020 by Rick York
I am not going to write any code for you. You need to do that. I will give you one tip though. It has to do with this part : (1 + monthlyInterestRate)^(numberOfYears * 12) You can use the pow function for this. It would look like this : pow(...
13 Aug 2020 by Patrice T
Quote: please help me with this, This requirement comes from a challenge site, it is a challenge to you by you, it looks like you failed. You show no attempt to solve the problem yourself, you have no question, your main effort is pasting the...
12 May 2013 by compuknow
Is it possible to access each bit in a byte using C++. For example if i havechar * a = NULL;a = new char[500];orchar a[500];Like how one accesses each individual element using its index , is there any similar method to access each bit in C++.Please mention a method...
13 May 2013 by CPallini
Suppose, for generality:const int N = 500;a = new char[N];char b[N];You access bit bitno of either a or b in the same way (note: not tested):int getbit(int bitno, int x[], int size){ if ( bitno = (size*8) ) { // throw an exception here } int...
5 Apr 2017 by Shao Voon Wong
Compute Concurrent Permutations and Combinations on CPU
30 Jul 2019 by Shao Voon Wong
Run your C++ Graphics on the Desktop and Web
25 Apr 2023 by Shao Voon Wong
Bring your animations to H264/HEVC video using C++ and C# with h/w acceleration
28 Jun 2019 by Shao Voon Wong
How to bring your C++ code to the web
21 Jul 2019 by Shao Voon Wong
Bring your existing WPF and Winform application to the Microsoft Store
18 Nov 2018 by Member 14058861
So, the algorithm works by sorting in the end, but not ouputting correctly line by line. pls help, i do not understand what is wrong with my code. What I have tried: #include using namespace std; int main() { int temp; int end = 10;//each time loop completes for i,the end will...
18 Nov 2018 by Patrice T
Because you are comparing element at index i and the next one if (arr[i] > arr[i + 1]) { you need to pay attention to the end value of loop. i+1 must not go beyond the end of arr. ----- Your code do not behave the way you expect, or you don't understand why ! There is an almost universal...
18 Nov 2018 by Rick York
I think your loops should be written like this: #define CountOf(a) sizeof(a)/sizeof(a[0]) const int arraySize = CountOf( arr ); for( int m = 0; m
18 Nov 2018 by CPallini
Try #include #include using namespace std; int main() { array arr{ 44,9,237,1,5,44,534,17,21,819 }; for ( size_t m = 0; m arr[n] ) swap( arr[m],...
5 Oct 2011 by viapauline
i need a sample problems and codes for c language
5 Oct 2011 by killabyte
yes given problem where shall i begin
6 Oct 2011 by killabyte
#include "stdio.h"#define LAZY_CODER 1#define UNAWARE_OF_GOOGLE 1void DoNothingLearnNothing(){ printf("...");}int main(){ while(LAZY_CODER && UNAWARE_OF_GOOGLE) { DoNothingLearnNothing(); } return 0;}
30 Mar 2020 by Member 14771149
in this function it always display an error that a and b are initialized variables, but i think there is more problems in the code What I have tried: #include using namespace std; void PosNeg(int* arr, int n, int* a, int* b, int&...
30 Mar 2020 by CPallini
This fixes that (ugly, as you've already been told) C++ code #include using namespace std; void PosNeg(int* arr, int n, int* &a, int* &b, int& cn, int& cp) { cn = 0, cp = 0; for (int i = 0; i
30 Mar 2020 by Rick York
Start by looking at what happens to the variable a in the function main. It declared as a pointer to an integer and it is not initialized. It is passed to the function PosNeg. To review, it is an uninitialized pointer passed by value to a...
30 Mar 2020 by Stefan_Lang
Solution 1 does a good job of fixing all your errors. However, most of these errors wouldn't have been possible if you had used C++ features instead. Here's a different solution that avoids most of the pitfalls you've fallen into: #include...
21 Jul 2013 by Nish Nishant
This is a quick overview of ISO C++ 11 compiler features that are supported in VC++ 2013 Preview
4 Apr 2015 by BrainlessLabs.com
In this tip series, we will create a small C++ game engine.
18 Oct 2021 by Code_bro
Hi, like to do following. I want to derive multiple classes out of my base class. All of them have there own function called notify. But i do not like to have any kind of case distinction in the main() but just call a base function to make that...
17 Oct 2021 by Greg Utas
Define notify as virtual in base and override it in derived1 and derived2: class base { public: virtual void notify() { } } class derived1 : public base { public: void notify() override {...}; } class derived2 : public base { public: void...
17 Oct 2021 by Rick York
You can also make your class abstract which will require that derivations of it are implemented and it will prevent the base class itself from being instantiated. Here is how that might look : class BaseClass { public: void fn(int i) {...
8 Dec 2018 by CalicoSkies
Mixing audio from multiple WAV files to a single WAV file. Includes a C++ class for reading and writing WAV audio files, derived from an AudioFile class for future support of other audio file formats.
28 Oct 2015 by RegexNoob
I'm trying to use this class as it's part of WinHttpClient, but I get the following errors (It works on Unicode, but then unicode breaks all my code so I figured I'd fix that instead):Erreur 2 error C2664: 'ATL::REParseError ATL::CAtlRegExp::Parse(const char *,BOOL)' :...