14,734,247 members
This competition has ended

## Best C++ Article of December 2017

### Contribute to CodeProject and you'll automatically be in the running for a monthly prize!

Each month at CodeProject we gather together the best of the articles submitted the previous month and ask our readers to choose the best of the best. Entry is automatic - just submit you articke and we'll do the rest.

Check out the submission guidelines for information on posting articles.

## Current Entries

Articles that match the contest criteria are automatically entered. The top 50 entries are shown.

6 Dec 2017
Building a custom-designed PCB for an Internet of Things (IoT), “connected” device from scratch
10 Dec 2017
Make your class non-copyable without Boost
16 Jun 2018
Overloaded Operators to write concise code on STL Set Algorithms
15 Dec 2017
Step by Step Performance Optimization with Intel® C++ Compiler
15 Dec 2017
Full code line in header: GenericValue& SetInt(int i) { this->~GenericValue(); new (this) GenericValue(i); return *this; } The technique is called "placement new". It seems to be a Visual Studio problem: Make DEBUG_NEW work with placement new – Visual Studio[^]: If DEBUG_NEW is defined in...
8 Dec 2017
You need some logic for your printing. A function which resolves some problems. int input = 0; //Do a check of input while( (input % 4) != 1 ) { input = AskFromUser(); } int row = input//looks like the values are the same int colums = input;//looks like the values are the same for( int y =...
20 Dec 2017
Because this looks like homework, I will not give you code. But I can tell you what to do: Perform a modulo division by 10 to get the ones (0 to 9). Divide the value by 10. Repeat the above steps until the value is zero. With the second iteration, the modulo are the tenth. They can be...
28 Dec 2017
Putting all else aside, which is not easy int *p=a+2; // Increments two sizeof(int) - that is, two elements NOT two bytes So, since a is the address of a[0] then a+2 is the address of a[2] That means it's pointing to 9. If you increment 9 it give you 10. Make sense, now? Good. Now go study...
11 Dec 2017
Download it[^] and try (using at first a C++ Console project) to compile and run some of the examples.
1 Dec 2017
You don't need arrays, for such a computation. Modify your code to conpute results on the fly.
2 Dec 2017
This is a codeChef contest, it means that the answer is never the most straight forward. The whole codeChef site is about optimization, optimization is about reducing runtime and reducing memory footprint. In other words, for everything you do, you have to ask yourself why you do something, what...
2 Dec 2017
Try the KISS method, i.e. Keep It Simple, Stupid. Start with the basic problem N rows and N columns gives the total number of rooms. N = 3 // simple test value totalDiamonds = 0 FOR row = 1 to N BEGIN FOR column = 1 to N BEGIN roomNumber = row + column evenDigits = //...
2 Dec 2017
If you really need to covert it than: Use C stdio facilities instead of C++ streams. Transform your hotel class into a C struct (thus holding just the data members). Trasnform all the hotel methods into standard C functions, getting a pointer to the hotel struct as argument. e.g. #include...
3 Dec 2017
Never use multiple increment/decrement on same variable inside a formula, the result is unpredictable with C. b=++a + ++a+ ++a; Because C can rewrite code, b can be anywhere between 33 and 39. The result will vary between compilers and depending on compiler's options.
8 Dec 2017
I have formatted the example outputs so that they are shown with a fixed font. Have a look at them and you might find the algorithm. Think about how you would draw it with a pencil on a graph paper (here with one based x/y indexes): 1,1 - 1,N - N,N - 1,N - 1,3 - N-2,3 - N-2,N-2, .... An...
8 Dec 2017
If you need properly aligned numbers (if I got you), then try #include #include int main() { int noofpotato=1; int day=1; int month=1; while(month
8 Dec 2017
you can do something like right padding as below printf("Month:%6d\t\t Day:%6d\t\t Potato:%d\n",month,day,noofpotato); Output: Month: 1 Day: 1 Potato:1 Month: 2 Day: 2 Potato:1 Month: 3 Day: 4 Potato:1 Month: 4 Day: 8 Potato:1 Month: 5 ...
8 Dec 2017
}while(name[2]==END); That is not a valid statement. Also, if name[0] is not greater than 'M' then it will print the line about red team. Try indenting your code properly and the illogic will become clear.
9 Dec 2017
Quote: Can you suggest me how to learn to programme? It will be of great help. This is another question. Here is a standard answer: You have to know that you can do pretty much anything in any language, simply some languages are harder for beginners because there is more pitfalls to handle....
10 Dec 2017
You can't create an array with dynamic size before knowing that size. int x; int arr[x]; // you create the array here int i; printf("Enter the value of 'x'\n"); scanf(" %d", &x); // you know the array size here Advice: use the debugger to check that anything goes as...
10 Dec 2017
As others already noted, you need to create the array after you know its size. With a C99 compliant compiler (like GCC) you may write: Please note: in order to simplify the code, I have omitted checking the scanf return value. You should always perform such a check in the actual code. #include...
11 Dec 2017
Short answer: C implicit type conversions (google that term to see more) and printf %d specification. Try %u instead of %d.
18 Dec 2017
int compare_str(char info[][20]) void swap(char info[20]) Never put an array size in function declaration. Your code is all wrong, you need to learn how to use pointers because you want to swap names in array on main from a subroutine. c=compare_str(info[20]); How do you tell which names to...
18 Dec 2017
The correct implementation of your swap function would be void swap( char pa[], char pb[], int size) { char t; int n; for (n=0; n
18 Dec 2017
Your info is a two dimensional array of chars where info[index] accesses an array of NULL terminated strings of type char[] resp. char*. These are commonly called string pointers. When comparing these uing the == operator, you compare the pointers (the addresses). To compare the content (the...
19 Dec 2017
C is zero based, it mean that in an array of 20 elements, their positions are from 0 to 19. void swap(char *ap, char *bp) { printf("swap"); char tmp[20]; int x; for(x=0;x
19 Dec 2017
If "k" doesn't get printed, then swap is not being called. If swap isn't being called, then the body of the while loop in compare is never being executed. That means that the condition is not being matched. So why not? That's the question. And that's up to you to find out - debugging is a part...
19 Dec 2017
You were told yesterday: use the debugger. Why my program can't swap (help~~~~~)[^] Look at what is happening to your variables while the code is running. But that is odd code ... why are you incrementing loop variables twice? for(i=0; i
19 Dec 2017
Don't you think you missed something here: char *ap; ap=info[i]; char *bp; bp=info[i+1]; for(i=0; i
19 Dec 2017
I suggest you to 'divide and conquer': Use two functions, one for string comparison and another one for sorting: int compare( const char * sl, const char * sr) { //implementation left to the OP } void sort( const char * info[], int items) { // implementation left to the OP // uses the...
24 Dec 2017
x = 0 sets the value of x to 0, whereas x == 0 is 'true' if x equals 0. Let's take a look at your if statement in the first code block: if (x = 0) x = 0 sets the value of x to zero, but this expression has the new value of x (thus zero) as return value. So this if statement is equivalent to...
25 Dec 2017
it very easy pointer arithmetics:struct st *pointer = &info[0];//getting pointer to address of first struct char c = 'a';//search char int pos = -1;//external scope of var for( pos = 0; pos name[pos] == c )//check break; } Consider learning C...
28 Dec 2017
Here's the fun bit: I don't like that code. It's the last bit that says "NO!" to me: strcpy(dst,leng); leng is defined as being the size of the output - but there is no guarantee that dst has that much space - and since you are inserting a chunk of data in the middle of the original content of...
30 Nov 2017
Code from comment: UINT nCurrentState = (m_FilestreeCtrl->GetTreeCtrl().GetItemState(hChildItem,TVIS_STATEIMAGEMASK)>>0xC); You are not querying a check box state but the state image index. This index defines which image from the state image list is actually shown. By convention an index of...
6 Dec 2017
You could use regular expressions. Try, for instance #include #include #include #include int main() { std::string s = "18/1/2000##56"; std::cmatch cm; std::regex rgx("\\d+/\\d+/(\\d{4})##(\\d+)"); bool success = std::regex_match ( s.c_str(), cm,...
6 Dec 2017
The warning is thrown because the parameter is declared as _Reserved_. In such cases NULL should be passed. The ExtractIcon function (Windows)[^] documentation is unclear here. With other functions, the documentation usually states explicitly that the parameter should be NULL. I suggest to...
7 Dec 2017
Hi SOLVED: See end of question I've written a simple server in C++ which simply listens for connections, assigns a ClientConnection class to each connection, and those sockets receive messages. When my separate client app connects to the server, the connection is acknowledged but the server...
8 Dec 2017
Do you have any idea how much work explaining code line by line is? Every single line needs a paragraph of explanation! For example: int next = r.Next(); Create a new variable called "next" which can hold a integer value. From the previously declared Random instance "r", call...
10 Dec 2017
Your code is very C-like. Please, consider maintaining the student properties (e.g. name and assignements) in a class (or struct). Consider using std::vectors instead of plain C-like arrays. Finally, consider using std::uniform_int_distribution[^].
11 Dec 2017
In my opinion, the easiest way would be to use a flag : bool empty = true; for( int i = 0; i
12 Dec 2017
Try to use CDatabase Class[^] : // This fragment is taken from the declaration for CMyDatabaseDoc // CMyDatabaseDoc is derived from CDocument. public: // Declare a CDatabase embedded in the document CDatabase m_dbCust; m_dbCust.OpenEx(_T("DSN=MFC_ODBCTest;UID=JOES"));
13 Dec 2017
I don't know of a reliable way to write the BIOS alarm (wakeup) clock. You might get code and documentation from a mainboard manufacturer to read and write the CMOS memory where the alarm clock values are stored. But this is always mainboard and BIOS specific. It might also not work with modern...
13 Dec 2017
The keyword is C/C++ pointer arithmetic. The first parameter of the AfxMessageBox() function is an LPCTSTR string pointer. You are passing the address of a constant string and adds the value "5" (myNode.m_Identifiant_Noeud is as primary key probably some kind of int). So the message box shows...
13 Dec 2017
The compiler chooses the version that matches in the context: // The const version is used here uchar c = *var.ptr(); const uchar *p = var.ptr(); // The non const version is used here *var.ptr() = c; uchar *p = var.ptr(); It is not really necessary to provide the const version but it is...
14 Dec 2017
Take a look at this project: Colored/Blinking Controls and Dialogs with any Font[^]
14 Dec 2017
I would expect that they exist until CloseMsgQueue() is called for all handles returned by CreateMsgQueue() using the same name. Then there is no need to check if a queue is alive because it is under control of the application. The application can simply clear the handle variable after closing...
16 Dec 2017
It is an ellipsis, that indicates that the function takes a variable number of arguments after the first one. The printf function is a case in point. See va_arg, va_copy, va_end, va_start[^] for a sample implementation.
16 Dec 2017
We do not do your homework, we don't improve your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action. Us...
17 Dec 2017
Try, for instance #include #include using namespace std; int main() { std::smatch sm; string content ="[\nname: bin1\ntype: static\npx: 14\n]\n[\nname: car1\ntype: static\npx: 14\n]"; while (regex_search(content, sm, regex("\\[([^\\]]+)\\]"))) { cout
19 Dec 2017
It has been merged into the C++17 standard: std::filesystem::directory_iterator - cppreference.com[^]. If you still want to use the Boost implementation (and not compiling with C++17 support) you must use an older Boost version or check if it is still there but requires a definition to be enabled.

## Current Participants

Those with articles that match the contest criteria are automatically entered.

 Software Developer (Senior) United States
I have over 10 years of experience working with Microsoft technologies. I have earned my Microsoft Certified Technology Specialist (MCTS) certification. I'm a highly motivated self-starter with an aptitude for learning new skills quickly.
 Software Developer (Senior) Biotecnica Instruments S.p.A. Italy

Debugging? Klingons do not debug. Our software does not coddle the weak. Bugs are good for building character in the user.
-- The Klingon programmer

Beelzebub for his friends [^].

 United States
You may know us for our processors. But we do so much more. Intel invents at the boundaries of technology to make amazing experiences possible for business and society, and for every person on Earth.

Harnessing the capability of the cloud, the ubiquity of the Internet of Things, the latest advances in memory and programmable solutions, and the promise of always-on 5G connectivity, Intel is disrupting industries and solving global challenges. Leading on policy, diversity, inclusion, education and sustainability, we create value for our stockholders, customers and society.
Group type: Organisation

42 members

 Engineer Germany
Jochen started programming in the 80s using Assembler (Z80, 8080, x86), BASIC, C, and TurboPascal. Actually he uses mainly C++. He is a graduate engineer in communications engineering (University of Applied Sciences Kiel, 1991).
 Software Developer Germany
I am living in germany and now living from programming for some Years. In my spare time I like sports as jogging, playing football (soccer) and basketball.

We must take care for our planet, because we and our family has no other. And everybody has to do something for it.
 Software Developer Germany

I'm a software developer living in Germany with my family (wife & 2 sons).
My hobbies: sport, traveling, books (former reading, now hearing).
Welcome to my homepage: http://leochapiro.de
 CEO Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?
 Database Developer France
I am a professional programmer.
Problem analyse is certainly what I am best at.
My main programming expertise is in the xBase languages (dBase, Clipper, FoxPro, Harbour, xHarbour), then VBA for Excel and advanced Excel WorkBooks.

I also have knowledge on C/C++, d language, HTML, SVG, XML, XSLT, Javascript, PHP, BASICs, Python, COBOL, Assembly.
My personal interests goes to algorithm optimization and puzzles.
 Software Developer (Senior) retired Australia
No Biography provided
 Retired United Kingdom
I was a Software Engineer for 40+ years starting with mainframes, and moving down in scale through midi, UNIX and Windows PCs. I started as an operator in the 1960s, learning assembler programming, before switching to development and graduating to COBOL, Fortran and PLUS (a proprietary language for Univac systems). Later years were a mix of software support and development, using mainly C, C++ and Java on UNIX and Windows systems.

Since retiring I have been learning some of the newer (to me) technologies (C#, .NET, WPF, LINQ, SQL, Python ...) that I never used in my professional life, and am actually able to understand some of them.

I still hope one day to become a real programmer.
 Software Developer (Senior) United States
No Biography provided
 Chief Technology Officer Data Dock Consultancy Ireland
Scott Tattersall

I've spent the last 15 years working with the latest technologies and in both my own start-up companies, SMEs and large publicly traded companies. My previous software company for which I was both co-founder and C.T.O. was acquired in 2015 and since then I've been working with the latest technologies such as advanced Machine Learning (e.g. Google's Tensorflow), Computer vision (e.g. OpenCV), IoT (e.g. Arduino, RPi) and Crypto-currencies (e.g. BitCoin, Ethereum).

I mix knowledge of the latest technologies (Blockchain, Docker, etc) with deep experience on traditional and modern databases (Relational, Non-relational, document store, column databases, etc) and cloud deployment, architecture and infrastructure (Docker, Kubernetes, AWS, etc)

I currently work as a freelance software consultant (dock.ie)
 Software Developer (Senior) Singapore
Shao Voon is from Singapore. CodeProject awarded him a MVP in recognition of his article contributions in 2019. In his spare time, he prefers to writing applications based on 3rd party libraries than rolling out his own. His interest lies primarily in computer graphics, software optimization, concurrency, security and Agile methodologies.

You can reach him by sending a message on CodeProject or at his Coding Tidbit Blog!
 Student Belgium
Also known as ProgramFOX. I like programming, playing chess and astronomy. Administrator of Chess Variants Training[^].

Find me on:
 United Kingdom
No Biography provided
 Software Developer Bitmask Design, LLC United States
In real life, a research chemist. Bitten by the bug for instrument automation, and then numeric and kinetic modeling, I turned to the dark side (or to the light), programming all sorts of lovely things. Alas, one needs to make a living, so off I went to POS, and now, the insurance industry.

Useful stuff: reducing concepts to bare abstractions and then coding as generic a solution as possible (implicitly extensible). In a sense, applications that "don't care" about much to do their job.

Doing now for money what I used to do simply for pleasure - not much different than a cheap hooker.

At best? An Optimistic Cynic. - No better; No worse - as though you cared, and as though your caring really mattered.

Pathological Genius

I have done things . . .

"Dispensing wisdom and chaos with uncanny poise and unflinching bravado."

 First Prize Scott Tattersall -  Building IoT devices: from Maker prototypes to Custom PCB manufacturing Prize pool CodeProject Mug - CodeProject Second Prize Petrov Vladimir -  Avi from Image Files in One Click Prize pool Bob Sticker - CodeProject

## Contest Entries and Requirements

1. The contest period covers the the first day of the month 12AM US Eastern Standard Time and ends the final day of the month at 11:59:59 PM US Eastern Standard Time. All entries must be submitted during this period in order to qualify.
2. Entries must be an article, or blog entry.
3. With the exception of the Everything Else category, the article must be tagged with at least one of the tags corresponding to that competition's category (for example, to enter the C# Competition you would need to tag your article with a C# tag).
4. Articles entries must follow the CodeProject submission guidelines.
5. No cheating, lying, plagiarizing articles, chicanery, or kicking.
6. Articles may only be considered for a single category. If an article is eligible for multiple categories (for example, it pertains to both the C# and Web Dev categories), CodeProject editors and judges will decide which category the article shall be entered in.
7. No author can be nominated twice in the same category.
8. If an author writes has two separate articles, each article may be considered in their respective categories provided none of the aforementioned rules are broken. For example, if an author wrote two separate articles, one related to C# and one related to VB.NET, the author and articles could be nominated in the C# and VB.NET competitions, respectively.
9. In the event an author wins multiple competitions, and repeat, identical prizes, the number of prizes issued is solely at the discretion of the prize issuer.
10. In the event an article has multiple authors and/or contributors, the number of prizes issued is solely at the discretion of the prize issuer.
11. In the event of a tie,  the number of prizes issued is solely at the discretion of the prize issuer.
12. Multiple votes from the same IP will be automatically disqualified.
13. The judges’ decision is final and no correspondence will be entered into.
14. Only those who live in jurisdictions in which this contest is legal may enter.
15. Any breach of the rules and the prize will be awarded to the runner up.
16. By entering the contest you agree to the rules, conditions of entry, and agree that your member alias and any submitted material can be used for promotional purposes by CodeProject.
17. Entries shall be deemed to be submitted by the authorized account holder of the email address submitted at the time of entry unless clearly indicated otherwise. "Authorized account holder" is defined as the natural person who is assigned to an email address by an internet access provider, on-line service provider, or other organization (e.g. business, educational institution, etc.) that is responsible for assigning email addresses for the domain associated with the submitted email address.

## Eligibility

This competition is open to software development professionals & enthusiasts who are of the age of majority in their jurisdiction of residence; however, residents of Quebec and of the following countries are ineligible to participate due to legal constraints: Cuba, Iran, Iraq, Libya, North Korea, Sudan, and Syria. Employees (or a member of their immediate family) of CodeProject or any of their affiliates, subsidiaries, advertising or promotional agencies are also ineligible to participate. Void where prohibited by law.

## How to Enter

Entry is by the submission process described above. Please read the submission requirements before submitting your entry and ensure the article is tagged with at least one of the tags corresponding to that competition's category.

Lost, late, misdirected, or illegible entries will be disqualified. Any entry containing content that CodeProject deems objectionable for any reason will be disqualified. All decisions of CodeProject with respect to any aspect of the competition, including, without limitation, the eligibility of entries, are final and binding on all entrants in all matters as they relate to this competition. CodeProject reserves its right to modify the Rules.

CodeProject assumes no responsibility for lost, late, delayed, destroyed or misdirected mail, voice messages, email or any computer errors or malfunctions. No correspondence will be entered into with entrants.

CodeProject does not assume any responsibility for incorrect or inaccurate capture of entry information, technical malfunctions, human or technical error, lost, delayed or garbled data or transmissions, omission, interruption, deletion, defect or failures of any telephone or computer line or network, computer equipment, software or any combination thereof. Entry materials/data that have been tampered with or altered are void. If for any reason, in the opinion of CodeProject in its sole discretion, the competition is not capable of running as originally planned, or if the administration, security, fairness, integrity or the proper conduct of the competition is corrupted or adversely affected, including by reason of infection by computer virus, bugs, tampering, unauthorized intervention, fraud, technical failures or any other causes beyond its control, CodeProject reserves its right to cancel, terminate, modify, amend, extend or suspend the competition including cancelling any method of entry, and select a winner from previously received eligible entries. CodeProject reserves its right in its sole discretion to disqualify any individual it finds to be tampering with the entry process or the operation of the competition or to be acting in violation of the Rules or otherwise in a disruptive manner. CodeProject reserves its right to seek remedies and damages to the fullest extent of the law for any attempts to deliberately damage the competition web site or to undermine the legitimate operation of this competition. CodeProject shall not be held responsible for any errors or negligence that may arise or occur in connection with the competition including any damage to an entrant's computer equipment, system, software or any combination thereof, as a result of their participation in this competition or from downloading any material from the competition website where applicable.