Click here to Skip to main content
15,885,216 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 Score

C++11 

12 Jan 2020 by Shao Voon Wong
Floating Point Format For C++ and C# Programmers
13 Jul 2019 by Michael Chourdakis
An easy locking class for shared/exclusive mutex functions with upgrade/downgrade
23 Nov 2018 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.
13 Aug 2018 by Shmuel Zang
This article shows how we can implement a thread-safe events (similar to .NET events) mechanism using the standard C++ library.
30 Mar 2023 by Piotr Grygorczuk
Enable C++11 multithreading features in GCC for FreeRTOS
12 Nov 2020 by Miroslav Fidler
...but I will tell you anyway.
26 Oct 2022 by Shao Voon Wong
H264/HEVC Video Encoder for recording OpenGL rendering
29 Jun 2017 by EgorYusov
This article describes an efficient thread-safe reference counting system.
25 Feb 2018 by Petrov Vladimir
Weiler-Atherton algorithm in MFC codes demo implementation
30 Dec 2018 by Arthur V. Ratz
SVD in C++11 explained with an example
24 Jul 2018 by stevemk14ebr
PolyHook v2 - the C++17 x86/x64 library supporting multiple methods of hooking
11 Jul 2012 by Mikhail Semenov
keywords: constexpr, constant, constant expression, user-defined literals, GCC 4.7.0
23 Oct 2019 by David Lafreniere
A framework combining state machines with asynchronous multicast delegates
13 Apr 2015 by Anton Chibisov
This tutorial showcases how to implement C++ delegates which are capable of being bound to methods and functions having arbitrary signature, i.e., any number and type of parameters and return value.
23 Mar 2021 by honey the codewitch
Make your code more efficient by hacking your compiler to improve its optimization capabilities
16 Oct 2022 by Shao Voon Wong
C++11 Range For-Loop to Enumerate Registry, Folder and WMI
2 Aug 2016 by Evgeny Pereguda
Simple article about using of Desktop Duplication API for capture desktop screen WITH image of cursor
2 Jun 2014 by Bartlomiej Filipek
How memory access patterns can influence performance of your code
23 Oct 2015 by Michael Chourdakis
A simple template for manipulating the registry
30 Jan 2018 by Bartlomiej Filipek
It appears that in some cases memory allocated for the object controlled by smart_ptr might not be released until all weak pointers are also ‘dead’... let's see why
10 Jul 2018 by John M. Dlugosz
Did you realize that the `*this` object can be qualified with lvalue vs rvalue? Here’s what you can do with that.
26 Mar 2015 by BrainlessLabs.com
This tip describes a n ary tree structure.
16 May 2018 by Shao Voon Wong
C++11's std::conditional tip with an endian swap example
9 Dec 2018 by Richard MacCutchan
Because the sizeof operator returns an unsigned value. So the compiler then treats -1 also as an unsigned value. The hexadecimal value of -1 is 0xFFFFFFFF or unsigned decimal 4294967295, which of course is much greater than the size of an integer (which is 4 (not 8)). One of the pitfalls of...
24 Apr 2020 by Member 4201813
Jump forward/backward procedures for XorShift RNG explained step by step
15 Mar 2016 by Satbir S
A worker thread gives you parallel processing power
23 May 2018 by John M. Dlugosz
It is easier than ever to exploit the range-for loop (and make use of std algorithms) for things other than collections.
14 Apr 2020 by Member 4201813
Jump forward/backward procedures for XorShift RNG explained step by step
25 Oct 2014 by Bartlomiej Filipek
A list of my top 5 interesting C++ proposals.for pre-Urbana mailing. Unified Syntax Call, Coroutines, array_view ranges and modules.
11 Dec 2015 by Sergey Alexandrovich Kryukov
Probably this is because you act in identical way: create the brand new rd and genEngine objects each time you need a random value. You need to create and initialize these objects only once in the whole life cycle of your process. For example, create such objects in main and pass the pointer to...
10 Jun 2018 by Patrice T
Quote: My program to check for armstrong number is showing 153 as non armstrong number. Your problem is that you mix floating point functions and integer arithmetic. Consider than the floating point value of an integer is never exact, thus your problem. pow() is double.
14 Oct 2018 by Jon McKee
The reason for that output is something called pointer arithmetic. Arrays are stored sequentially in memory. So the offset from one value to the next is the size of the type. Integer = 4 bytes, float = 4 bytes, double = 8 bytes, etc. This is the fundamental reason why pointer arithmetic works....
4 Jul 2020 by Michael Haephrati
How to set write direction and alignment
5 Jul 2020 by CPallini
You could try to rewrite your program for using GDI+. Have a look at Getting started with GDI+ - Win32 apps | Microsoft Docs[^]
14 Dec 2020 by honey the codewitch
Some C++ magic to help cut down on heap abuse for simple scenarios
29 Jan 2021 by CPallini
Quote: void func(ENUM retCode, std::string name); What's wrong with ENUM func(std::string name); ? If you really need to return a value then return it. As an alternative you could pass an item by reference (see, for instance C++ Functions -...
25 Jul 2022 by OriginalGriff
Quote: My compiler: "error". "error". "error". "[Ha ha ha, another]error". First off, if you get compilation errors, then that is to be expected - but we can't help fix them without seeing the code and the error message(s) any more than a...
29 Mar 2012 by Sergey Alexandrovich Kryukov
You need to instantiate (construct) an instance of the class using new A(); new B(); actually, as per your code, in both cases it won't work; is is not even related with OPP as you simply try to re-reference NULL.[EDIT]The code actually works as OP described with C++ of VS 2008. Please...
6 Jan 2014 by OriginalGriff
Depending on what environment you are working in.For Native, call Sleep[^] - for CLR applications you want Thread::Sleep[^]But...be aware that it will do just that: pause your console for the time you specify. Nothing else will happen...
2 Sep 2014 by BrainlessLabs.com
C++11 Constructors and Copy Assignment – Part 2
8 Apr 2015 by Evgeny Pereguda
This article presents simple combination of Policy design pattern and Variadic Template Technique.
18 Sep 2015 by Shvetsov Evgeniy
Type tricks (above described and other)
10 Oct 2015 by CPallini
Quote:The console is only returning the yThat is the correct behaviour of the comma operator (see here[^]).Anyway a C/C++ function returns a single value.However, the single return value could be an object (instance of a class or a struct) and you may define the insertion operator for...
10 Oct 2015 by PIEBALDconsult
I didn't find a dir.h file with my installations of Visual Studio.But Borland C/C++ has a dir.h and GCC that comes with MinGW has one.It seems Visual Studio does not have a dir.h :"I think that ANSI C does not have any directory functions, hence no dir.h and no dirent.h in Microtosoft...
29 Oct 2015 by CPallini
Reflection is not supported by C++. You have to write a parser in order to accomplish such a task.
29 Oct 2015 by Sergey Alexandrovich Kryukov
Please see Solution 1.One interesting product of this kind can be found in Qt: http://vasc.ri.cmu.edu/media/manuals/qt.2.3.1/moc.html[^].See also http://woboq.com/blog/reflection-in-cpp-and-qt-moc.html[^].—SA
21 Nov 2015 by Sergey Alexandrovich Kryukov
This is done using regular Windows API CreateFile:https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx[^].Only you need to use appropriate string for a file name representing the disk, "\\.\PhysicalDriveX". See the explanations at the end of this MSDN...
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 Oct 2018 by OriginalGriff
Read it as a string, then - assuming it won't always have a "+" in the middle - process it into a collection of strings: a sequence of numerics becomes a string, a sequence of non-numerics becomes another. In this case you will end up with three strings:"12345" "+" "67890" You can then convert...
20 Oct 2018 by Richard MacCutchan
for(i=0; i
19 Nov 2018 by OriginalGriff
No, it doesn't have to be. The only way to be sure of an output order is to use an ORDER BY clause and reference a column that provides the order: an IDENTITY column, or a timestamp. As you add and remove rows from yoru DB, it leaves "gaps" in the data, which can be filled later to prevent...
30 Oct 2019 by Richard Deeming
HMAC is a one-way cryptographic hash function. You cannot retrieve the plaintext from the hash. HMAC - Wikipedia[^]
26 Nov 2019 by phil.o
void main(); Please remove that semicolon and see what happens.
27 Nov 2019 by Shao Voon Wong
Remove the i parameter and &ptrGrabResult std::thread t1([&]() { for (uint32_t i = 0; i GetCameraContext();...
10 Dec 2019 by Richard MacCutchan
You could start at C++ Language Reference | Microsoft Docs[^]. However, rather basic code but ... unsigned char uchars[5] = { 17, 17, 17, 17, 17 }; unsigned char* uresult = thefunction(uchars);
13 Jul 2020 by Peter_in_2780
You need to write scanf ("%g", &input1); to pass the address of your variable to scanf. Elsewhere, you're referencing values, so no & is needed or wanted.
13 Jul 2020 by Jon McKee
scanf - C++ Reference[^] Depending on the format string, the function may expect a sequence of additional arguments, each containing a pointer to allocated storage where the interpretation of the extracted characters is stored with the...
7 Aug 2020 by OriginalGriff
It's pretty simple: 1) Create a function which takes an integer parameter called limit 2) Inside the function: 2.1) Create a variable called sum and set it to zero. 2.2) Run a loop from 0 to limit inclusively. 2.3) Inside the loop: 2.3.1) If...
7 Dec 2020 by Richard MacCutchan
Read your code: look at your delete function, it does not do anything. int delete_node( node* head,node* pointer) //delete linked lists that user input { node* NEXT = head; pointer = head; return -1; // any following code will now be ignored.
20 Feb 2021 by Rick York
That "certain size" should give you a clue to what limit you have run into. A normal 32-bit application* will have a memory access limit of 2GB while a 64-bit app will have an enormous limit. In fact, you can not put enough memory in any...
7 Aug 2021 by Rick York
Yes, that memory needs to be allocated before it is used. A statement like this could be used : wcPt2D* vertRot = new wcPt2D[ nVerts ]; and, of course, it must be released after it is used : delete [] vertRot;
26 Aug 2021 by Richard MacCutchan
CSS Tutorial[^]
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...
31 Dec 2021 by Richard MacCutchan
You could probably simplify that by the use of the singleton pattern - Google Search[^].
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...
17 Jan 2024 by Bruno van Dooren
I wrote an article about that. Check it out. Using C++ Move Semantics to Manage Pointers to Externally Allocated Memory[^]
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;}
12 Feb 2012 by Andreas Gieriet
HTML page with all syntax/grammar productions of C++98/C++11
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...
6 Oct 2013 by Richard MacCutchan
You need to carry the public scope attributes forward to your inherited class, thus: class Parallel: public thread {
24 Dec 2013 by CPallini
In addition to Andreas good suggestion, I wonder if there is any article, here at Code Project, on the argument[^].
6 Jan 2014 by CPallini
In C++ round braces are mandatory in function calls.Change fromQuote: if (test=="yes"){ printmap; } toif (test=="yes"){ printmap();}You should also change fromQuote:string map[6][6];tostring map[7][7];in order to avoid buffer overrun.Finally...
6 Jan 2014 by OriginalGriff
You have look at your warnings!You have almost certainly got something like: warning C4551: function call missing argument liston this line: printmap;Beasue you are not executing the method, you are just referring to the method name.Change it to:if (test=="yes"){ ...
17 Oct 2015 by Andreas Gieriet
How about Google?E.g. see http://www.cplusplus.com/doc/tutorial/typecasting/[^].RegardsAndi
4 Nov 2015 by User 59241
You should be using ifstream for input.Read this: http://www.cplusplus.com/doc/tutorial/files/[^]and:http://www.cplusplus.com/reference/fstream/ifstream/open/[^]Then: ifstream studentfile; string studentfilename; cout >...
11 Nov 2015 by KarstenK
The easiest way is to close Visual Studio completly, rename the file and open the *.sln file with a text editor and search and rename it also. You can delete the database files because the get rebuild when missing. Make a backup of all data before starting. ;-)
21 Nov 2015 by Jochen Arndt
This line might be the source:fileStreamIn.read(&buffer.front(), buffer_size);The content of a std::string should not be modified directly. You are using front() here which allows the modification of the referenced character. But you are using it to modifiy the string content. Because...
8 Dec 2015 by Jochen Arndt
The local variable temp goes out of scope when the function returns and is no longer valid afterwards.So you should return a value here rather a reference:Human Human::operator++(int){ Human temp(*this); operator++(); return temp;}[EDIT]See also here...
15 Dec 2015 by Are Riff
I am learning about dynamic memory and have a question.Let say I have this class.class Elf {private: double _health = 0;public: Elf(const double &health){_health = health;}};I can create an Elf object using smart pointer like this.unique_ptr vec1 =...
17 Dec 2015 by Andreas Gieriet
See the definition of pop_back().E.g. from http://www.cplusplus.com/reference/vector/vector/pop_back/[^]. It says that pop_back() from an empty collection is undefined behavior, which includes "crashing".[EDIT]Your logic is broken: while(!human.empty() || !zombie.empty()) ... is also...
19 Feb 2016 by CPallini
removing duplicates is tricky, because you alter the vector content on-the-fly.The range loop is elegant but simply not suited for such a job. Try, for instanceauto itm = hall.begin();while(itm != hall.end()){ auto itn = hall.end(); while(--itn != itm) { if (...
2 Jul 2016 by Shvetsov Evgeniy
Assuming i have some function template f1:templateint f1(int i, int j) throw() { return i + j + f2(i, j);}is there way to determine if 'f2(i, j)' can be a constexpr. (no matter it is a func. or a functor) and so mark 'f1' as a constexpr. too?What I have tried:I am...
25 Jun 2016 by OriginalGriff
Indentation helps a lot when you look at code: it means you can see what is goign on a lot more clearly...But a quick glance says that the swap function:void swap(int *i,int *k){int j;// js any temperory element*i=*k;*k=j;}Is not going to work!What value do you put in k each...
2 Jul 2016 by Philippe Mori
As you can see, your first 2 functions declare the same function. This would be similar to:void g(float p[3]) { /* ... */ }vsvoid g(float *p) { /* ... */ }You can call either of these function (assuming only one is declared and defined) like this:float pos[3] {1.3f, 4.3f,...
19 Dec 2016 by OriginalGriff
Use the debugger. That's part of what it is there for.Put a breakpoint at the start of the function, and step through look at closely at what is going on. What may help you understand is if you draw out on paper first what the list looks like - set up a simple one with say 4 nodes - then...
23 Dec 2016 by CPallini
In order to replace a string, I would rather usefor ( vector >::iterator it = v.begin(); it != v.end(); ++it){ if ( it->second == "OldString") it->second = "NEWSTRING";}or, with C++11 for ( auto & x : v){ if ( x.second == "OldString") x.second =...
20 Mar 2017 by Jochen Arndt
The error is here:m_message = new char[strlen(value + 1)];That will allocate two characters less than required (random size when the passed string is empty).It must be:m_message = new char[strlen(value) + 1];The error is also present with G++ builds but not detected.
19 Jun 2017 by CPallini
If you need to insert blanks somewhere in the string (like your example suggests) then the string::insert method ( see string::insert - C++ Reference[^]) is your friend: #include #include using namespace std; int main() { string s = "hello"; s.insert(1, 1, ' '); ...
1 Oct 2017 by CPallini
C++ implementation of 2x2 Hill cipher
27 Apr 2018 by Patrice T
I see a few problems in your code, but they are not the problem you are hunting. results() is ending by calling mainEvent() which is the function that called it, generally speaking, it is a bad idea because it look like an unintended recursion. Each function should end by returning to caller. To...
29 May 2018 by Rick York
You don't need to define values for TRUE and FALSE. You have tagged this question as being for C++ and the language has the keywords true and false defined in it and that is all you need. Here is some pseudo code that should give you an idea. while( looping ) { if( array[m] +...
12 Jun 2018 by Rick York
The primary reason they are so useful is they make searching and finding values of interest very fast. The first item in the map is called the key and it used for searching. Usually a binary tree or something similar holds the data behind the scenes with the first value being the identifier...
13 Jun 2018 by Patrice T
Quote: yes i want to click the button from code. if variable entered in edit control box is even then button get clicked. This is a bad idea ! Imagine the user want to enter the even number 123456. As the user type the number, you have: 1 => odd 12 => even 123 => odd 1234 => even 12345 => odd...
9 Jul 2018 by Rick York
You can subtract two numbers and then test the sign of the result. A negative value means the second was larger than the first. You can determine the sign by testing the most significant bit - if it is set then it is a negative number. That can be done by masking off all other bits and...
24 Sep 2018 by Leo Chapiro
Visual studio 2017 is only an IDE and is not relevant for your task. If you mean the windows defender, take a look at API / Windows Defender Functions, for example at WDStatus function: Returns the current status of Windows Defender. HRESULT WDStatus( BOOL *pfEnabled ); The status of...
16 Oct 2018 by OriginalGriff
Assuming that the integer value is "days since 1/1/1900", then you have to convert that to a date. So each leap year has 366 days, and each non-leap year has 365. Leap years are all those years divisible by 4 in the range 1900 to 2099, so I'd create an array of "year counts" 0, 365, 365+365,...
19 Oct 2018 by David O'Neil
int main() { play(paper); play(something); play(scissors); play(paper); return 0; } Hope this helps get you started Or maybe it will make you mad enough to try on your own, and show this a***hole (being me) what a jerk I am by succeeding. Or at least...
7 Nov 2018 by Afzaal Ahmad Zeeshan
If you want to use C# because, then you have to leave all that pointer luxury with the C++. The core concept of C# was to enable you to have a managed environment, where you only had to write the business logic instead of having to manage the low-level memory and hardware as well. C# itself is...
11 Nov 2018 by OriginalGriff
First, decide what makes a word "end"? It is a space? Well yes - but the first word of this reply doesn't end with one, and neither does the last word of this sentence! Or this. (And this one doesn't start with a word.) 3 of the sentences in this paragraph don't! So start by deciding what...