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
20
votes
3answers
17k 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
304 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
12k 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
494 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. ...
2
votes
1answer
158 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
347 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
294 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
13k 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
6k 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
4k 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
623 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
731 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
832 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
447 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
29k views

Getting the length of a file in characters

Here's my function for getting the length of a file, in characters: ...
5
votes
3answers
7k views

Max repeated word in a string

I was trying to do a very common interview problem "Finding the max repeated word in a string " and could not find much resources in net for c/c++ implementation. So I coded it myself here. I have ...
4
votes
1answer
413 views

Anything I'm missing on this delegate implementation?

Just as the question states and to be sure, am I missing anything on this? Something important/obvious that I overlooked? As is, I can save any functor, function pointer and member function pointer ...
6
votes
2answers
466 views

Optimising a custom tree data structure

I have the following 'custom' tree data structure. This concept was to be thought of as, if given ("abb", 20) and ("abc", 30), then Tree['a']['b']['b'] == 20 <...
6
votes
2answers
2k views

Optimizing WordWrap Algorithm

I have a word-wrap algorithm that basically generates lines of text that fit the width of the text. Unfortunately, it gets slow when I add too much text. I was wondering if I oversaw any major ...
9
votes
2answers
5k views

OpenGL forward-compatible context creation on Windows

Is this the proper method for creating an OpenGL 3.3+ forward-compatible context? ...
5
votes
3answers
940 views

Quicksort application

What do you think about this code? ...
4
votes
3answers
12k views

Reverse a word using string manipulation

...
8
votes
1answer
209 views

Simplifying a Resizing Method

I'm making a simple container class for fun and education, but my rebuilding/resizing method seems rather inefficient. Is there an easier way to do this? ...
14
votes
2answers
15k views

C++ string_cast<> template function

In C++, to simplify string conversion between std::string and std::wstring, I created the following utility template functions: ...
6
votes
2answers
303 views

Counting the total number of characters in an std::set<std::string>

I have a std::set<std::string> and I need to know the total number of characters (sum of all strings length): ...
9
votes
6answers
5k views

Linked List program

This is a simple linked list program which creates a list by appending an object at the tail. It compiles and runs perfectly. Is the coding style, logic etc are fine? How can I improve this program? ...
14
votes
11answers
1k views

Design dilemma: extensibility vs simplicity

Here is my problem abstracted to Bird classes. I know that number of Birds will increase on the future and new behaviors might ...
11
votes
2answers
4k views

Improving HashMap in C++

I have created a HashMap<string,int> in C++. I would like help determining if it is good or bad. I have not handled the errors or successes with messages. I ...
14
votes
2answers
494 views

Retrieving list of flight numbers from flight path

The below is \$O(n^3)\$. I'm sure there is a way to improve this.. ...
13
votes
1answer
3k views

Path finding function

Could this be made more efficient, and/or simpler? It's a path-finding function. It seems to work, but do you see any potential cases where it could fail? ...
9
votes
1answer
263 views

Interpolating given value and legacy value from serialization buffer

Here's a function that interpolates between a given value and a value fetched out of a legacy serialization buffer: ...
16
votes
2answers
2k views

Eratosthenes sieve and MPI

I wrote this sieve of Eratosthenes with MPI, but I'm not sure if it's good enough. Should I use MPI_Scatter and MPI_Gather ...
12
votes
6answers
1k views

Class for holding person's information

I have written another program in C++. Excluding the point that the class definition should be in a separate header file, is there anything that needs to be improved? ...