Questions tagged [c++]

C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. This tag should be used for any question which requires knowledge or expertise with the C++ programming language. This is a general tag which is used for any of the C++ language standards (C++98, C++11, C++17, etc.). The question should identify the compiler being used, the operating system, and which of the C++ standards is being targeted.

Filter by
Sorted by
Tagged with
9
votes
1answer
5k views

Generic C++ Factory

For my project, I needed a way to instantiate different object types during runtime using "string names", for this I designed a generic factory that is created for each object hierarchy type (...
3
votes
2answers
447 views

Iterating over unequal unordered pairs in one collection

This code kinda hurts my feelings -- everything else in my code is done in neat one-liners, exploiting algorithms and, sometimes boost::bind, except for this piece. ...
7
votes
3answers
2k views

Custom integer class for calculating crypto algorithms

How can I improve upon this integer class that I wrote? I am/will be using this for some calculation intensive crypto algorithms, mainly POLY1305AES. I might even write RSA using this. I know that ...
5
votes
4answers
456 views

Truthy assignments

I often argue with the voices about the correctness of having assignments within an if statement (or equivalent), meaning having this: ...
10
votes
4answers
705 views

Critique my first C++ “Hello World” program

This is my first attempt to write a simple C++ program: ...
8
votes
1answer
501 views

Use of external memory or a custom allocator

I'm creating a class which uses a custom buffer. I want to offer the possibility to pass an external memory address (for higher interoperability between languages) or (for convenience) to specify a ...
6
votes
1answer
2k views

Fixed point combinator in C++1x

This has been tested and compiled under Visual Studio 2010. Are there any serious problems with this implementation? PS. This implementation is fully lambda expression based. If I can make ...
2
votes
1answer
2k views

How is my SFML sprite Move() function?

I'm making a pong game with SFML and in the process made a function that takes a Time, Speed, ...
2
votes
3answers
828 views

Finding social network of a friend

Following is the code which finds the social network of a friend (i.e. friends of friends and so on). Friends definition is, ff W1 is friend of W2, then there should be Levenshtein distance equal to 1....
6
votes
2answers
802 views

Bit-twiddling for a custom image format

The following code is mainly concerned with the conversion from byte/bit stream to numericals such as int, unsigned int, short int, unsigned short int, float, and etc. These functions are heavily used ...
26
votes
2answers
2k views

C++ API for interfacing with Lua

I wanted a good way to move objects back and forth between Lua and C++, and I didn't want to use anything like LuaBind or the other available libraries I could find, so I instead wrote this. It's ...
7
votes
3answers
6k views

Sales tax calculator

Please review the sales tax problem which has been designed using strategy pattern. The Problem: Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical ...
3
votes
1answer
564 views

Conditional parsing, non-standard approach

Conditional parsing (aka read some tokens and return true or false). As a solution to this SO question, I wrote following code: ...
5
votes
1answer
1k views

An implementation of “finally” in C++0x

I've made a quick finally type in C++: ...
14
votes
3answers
12k views

Simple text-to-binary converter written in C++

I am learning C++ on my own and was hoping for some feedback on this simple text-to-binary converter. The program runs and I haven't encountered any errors with it yet. Any input is welcome. ...
5
votes
2answers
10k views

Decoding binary coded decimal (BCD) value

I have 3 questions, all of them are concerned with binary coded decimal (BCD) conversion. My coding snippets are listed as follows. But I don't like my algorithm because it takes too long when dealing ...
6
votes
2answers
3k views

Avoiding the 'possible loss of data' compiler warning

I'm writing a file I/O DLL in C++ which is going to be used from VB6. The interface is already fixed, and uses INT64/Currency as the general integer data type. Now I have this function: ...
7
votes
1answer
7k views

Combining two 32-bit integers into one 64-bit integer

long long combine(unsigned int high, unsigned int low) { return ((unsigned long long) high) << 32 || low; } Is there a better name for the operation? Is ...
20
votes
3answers
16k views

makefile dependency generation

I need automatic dependency generation to be done in my makefile. So, I have tried to write one, after googling for similar ones. I have found some ways to do that, ...
4
votes
1answer
298 views

Text-based vertical scroller game

I'm making a simple text game using the pdCurses library and a few other minor things like a vertical scroller in which you avoid the randomly-generated walls. There are two walls on left and right ...
6
votes
2answers
1k views

Flattening a doubly linked list

I am a Java dev and trying to prepare for interviews in C++. Can someone please review the below solution for me? Assume that you are given the head and tail pointers of a doubly linked list where ...
4
votes
3answers
2k views

Does my Rectangle intersect code work?

I just want to see if any part of one "rectangle" overlaps the other. Is this the correct code? ...
2
votes
2answers
11k views

Fast import of numbers stored in a CSV file

I would like to efficiently import real numbers stored in CSV format into an array. Is there a way to modify my code to make it faster? Also, is there a way to scan the file and compute the number ...
18
votes
3answers
11k views

Generic C++ exception catch handler macro

I have this set of legacy C++ projects with a large number of public functions. At the start, none of those publicly exposed functions had try..catch insulation ...
8
votes
2answers
1k views

C-style array class

I often use C API's in C++ that force me to use C-style arrays. I got sick of constantly using a dynamic vector with &vec[0], so I wrote this C-style array ...
10
votes
1answer
483 views

Emulator for representing hardware and operating systems

This is an emulator I am currently re-writing for my Operating Systems course. It is a simple emulator that is supposed to represent hardware, OS, etc. It is strictly for learning purposes and I want ...
4
votes
1answer
2k views

Traversing a BST in iterative inorder

Traverse a binary search tree in iterative inorder. Note that the iterative methods below contain the meat of the code; the remaining code is included for completeness. ...
3
votes
1answer
155 views

How can i make my Get_Numb_of_Digits_in_a_number() function more accurate?

Here's my function but it sometimes has unpredicted results with entering different numbers but with the same number of digits getting different results. I figure it has something to do with a ...
7
votes
2answers
1k views

Homemade Stopwatch class

Here's some explanation for accuracy and neg_accuracy: It's meant to keep all the values in terms of what the user specified he ...
8
votes
2answers
2k views

Composition or Private Inheritance for Implementing Builder?

Over on StackOverflow, I was asked if I could come up with an example where private inheritance would be preferred to composition (in C++). The following is the situation I described, and I was ...
5
votes
1answer
1k views

C++ template meta sql

I wrote a wrapper around boost-mpl and transformed it to an sql engine. It is a compile time sql thing, not related to normal databases. I have not finished it completely. I have some problem with the ...
5
votes
2answers
297 views

Preparing interpreter for error-handling

This is a follow-up to the question that I posted earlier regarding my interpreter. After a lot of help, I refactored my code and added more functionality to it. Now, it allows users to declare ...
3
votes
2answers
290 views

Best syntax for executing an action between each loop iteration.

The question of the cleanest way to write a loop that executes some action between each iteration has always interested me. In a sense, what is the best way in c/c++ to implement this fictional ...
24
votes
5answers
1k views

Reading a collection of strings from the user

I was trying to write a program that will read a collection of strings from the user, and then end the moment it encounters a ".". So then I write a ...
6
votes
4answers
12k views

Polish notation interpreter/calculator

Just for the heck of it, I wrote a simple little interpreter that takes in inputs in the form of Polish Notation. The user will input something like + 5 6 And ...
12
votes
3answers
2k views

My own C++ Format function

I've never been satisfied with any of the possible sprintf()-like functions in C++: sprintf() is a C function and it's very ...
12
votes
4answers
5k views

Tic Tac Toe game

I don't have any questions about this piece of code; it compiles just fine in Visual Studio 2010. I just wanted to post it to see if anyone has any good ideas on how to simplify it, or pointing out ...
3
votes
1answer
2k views

String parsing with AVR-GCC

I'm working on interfacing some older positioning equipment with an arduino, but having done the majority of my work with higher level language I'm having trouble adjusting to the limitations of AVR-...
8
votes
1answer
3k views

C++ critical section with timeout

NOTE: My implementation is based on codeproject article by Vladislav Gelfer. Based on valdok's codes, I rewrote the critical section class. The difference is that my implementation integrated ...
10
votes
1answer
4k views

Small C++ Boost extension based on boost::property_tree

This is a small extension based on a boost::property_tree, which supports arbitrary values for the properties and appropriate serialization. It can be used as an ...
4
votes
1answer
3k views

Finding the k-th element in a BST

Given a Binary Search Tree, determine its k-th element in inorder traversal. Here's my node structure: ...
2
votes
3answers
1k views

Multi-Threaded Memory Preallocation

I need to figure out the best way to deal with memory pre-allocation Below is pseudo-code for what I am doing now, and it seems to be working fine. I am sure there is a better way to do this, I ...
7
votes
1answer
604 views

UTF-8 character reader function

You may see full code here (note that the link points to the specific commit). Language is "clean C" (that is, a subset of C89, C99 and C++98 — it is intended to compile under all of these standards)....
4
votes
2answers
3k views

Generating XML file from text input

I am hoping the code is readable as is. I can probably just print the XML using streams but I have other reasons for using the library. Please offer any inputs on how to improve program design/...
9
votes
2answers
727 views

Monster token parser function

This function will read an expression (made up of tokens) from the vector of tokens passed into it. It will remove the tokens that make up the expression from the vector and return them. A token is ...
2
votes
3answers
814 views

Optimizing my code that simulates a database

Some days ago I made you a question and I got some really useful answers. I will make a summary to those of you who didn't read and I will explain my new doubts and where I have problems now. ...
8
votes
1answer
428 views

Parsing a basic scripting language

I'm working on writing a scripting language with ANTLR and C++. This is my first actual move from ANTLR grammars into the C++ API, so I'd like to know if this would be a good way to structure the ...
3
votes
1answer
40k views

Deleting a linked list node

This is a classic linked list problem. Deleting a node from linked list given the data to be deleted. Inserting a node in a sorted linked list. I saw various versions of this and here is my version. ...
7
votes
5answers
29k views

Find the non repeating number in the integer array

The program finds the non repeated number in a int array. I am using a count for the duplicates and making a ...
8
votes
4answers
26k views

Getting the length of a file in characters

Here's my function for getting the length of a file, in characters: ...