Questions about C++, a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language.

learn more… | top users | synonyms

-4
votes
0answers
40 views

Why 1 bytes has 8 bits? [duplicate]

Past time Latin language was used in computer for giving command ,Latin language has 256 characters,for represent 256 word 8 bits was used . 2^8=256 8 bits are enough for representing 256 character . ...
2
votes
1answer
110 views

Tips for understanding big project fast? [duplicate]

I've got a job and many new things to be learned. The first thing is to understand big project, writtened mostly in C++, using Visual Studio. So, I see a statement, and I want to find its definition. ...
0
votes
0answers
4 views

From data file to Multi-Dimensional vector problems [migrated]

I am trying to write a "text adventure" engine that runs off of text and data files. I understand the concepts of arrays and multidimensional arrays, but know they cause memory leaks and not ...
0
votes
0answers
36 views

Tracing and visualizing trace on a timeline

I am working on a c++ library, which performs frequent communication with a piece of hardware. I need a way to instrument my code with tracepoints, that I can afterwards visualize the execution of on ...
-2
votes
1answer
46 views

Unexpected compilation error [on hold]

I wrote this. doesn't matter what am I supposed to do with it. It just doesn't complie! Using G++ 4.9 In the line which I insert data into the set I get error! commenting out that line will solve the ...
-3
votes
0answers
57 views

I want to build a software with C++, book list is needed [on hold]

Can you tell me where i can start from, I have already learned c++. I want to build a software with C++, book list is needed.
-4
votes
1answer
78 views

In my code everything works fine, when i debug i always get a 0 for smallest. why? [on hold]

NOTE I JUST STARTED LEARNING C++. THIS IS SCHOOL WORK AND WOULD APPRECIATE IT IF SOMEONE TAUGHT ME INSTEAD OF GIVING THE ANSWER. int a = 0; int b = 0; int c = 0; int sum = 0; int average = 0; int ...
0
votes
1answer
88 views

How shall I handle event loop exceptions?

What is the best practice for handling exceptions thrown from event handlers/listeners in a event loop? For example: class EventLoop { public: void start(); //create a thread which calls run(); ...
1
vote
1answer
160 views

Why does this algorithm work in O(n m)?

This is from a blog post on Codeforces. I couldn't really understand why the editorialist goes on to claim that this code works in O(n m) This is a graph problem, where we are supposed to find the ...
-1
votes
0answers
55 views

Setting Default Parameters in C++ [migrated]

I have a little question about how default values are given to function parameters in C++. The problem I faced is probably due to my lack of understanding as to where the parameters are supposed to be ...
1
vote
2answers
139 views

Why does this implementation of Dijkstra's algorithm work in O(n^2)?

Here is the code I use for implementing Dijkstra's algorithm. Consider a graph with n vertices and m edges. Shouldn't it run in O(n^2 m) ? Someone may say that there are n vertices and each edge gets ...
-4
votes
0answers
41 views

“= default” about constructor in c++ [on hold]

struct Sale{ Sale () = default;//I got nothing about those cod Sale(std::istream &input); Sale(const std::string &s):book(s) {} //and so on...... } What did the second code mean? Is that ...
-5
votes
0answers
23 views

Why the output of my programme is 495 instead of 496 [migrated]

#include<cstdio> #include<cstdlib> #include<iostream> #include<cmath> using namespace std; class obj { int arr[100],i,nod,sum; public: int init() { ...
-1
votes
0answers
34 views

Binary Search scheme alteration [closed]

I'm having a bit of an issue with programming an algorithm..... below would involve some of the details of the assignment; now before you begin to say that I should actually attempt, in solving this ...
-6
votes
0answers
52 views

Can I balance a full-time job and a programming internship? [closed]

Though I didn't get my degree in Comp Sci, I studied in Finance (BA) and Economics (MS) and have picked up programming as a hobby that I'd really like to incorporate in my career. My initial thought ...
-3
votes
1answer
233 views

If-else in C++ Programming Language [closed]

I am a little bit confused about this code. Why does the else block get executed? Please explain it. int a=10,b=20; char x=1,y=0; if(a,b,x,y){ cout << "A" << endl; }else{ cout ...
1
vote
1answer
159 views

Using streams to connect programming languages

I'm trying to run a computation-heavy program that creates an image on a website. Is it possible to compute in C++ and have an output stream that connects to an input stream in Node.js to display an ...
1
vote
0answers
54 views

Maximizing reuse out of a function primitive in CUDA

I'm working on the implementation of a few related algorithms in CUDA, all of which require a primitive that we'll call f(). The related algorithms can't simply call f though, as they require f to ...
2
votes
1answer
110 views

Genetic Algorithm's Tournament Selection limit to be selected

I started working again on a Genetic Algorithm and i'm trying a lot of operators and ways of selection. When I made the Tournament Selection , I noticed that it gets really easy to always get the top ...
-2
votes
0answers
40 views

package management for C++ project [closed]

I am a programming student looking to apply my programming skills to develop a custom C++ project. My project is an educational software project that includes a main interface that allows the user to ...
-1
votes
0answers
13 views

C++ , string in a function has always the same length [migrated]

What is wrong with this code? input has always the length of 4 in my function test, no matter if my string is actually longer or shorter. #include <iostream> #include <string> using ...
-2
votes
0answers
50 views

Graphing Logical circuit C++ Programming [closed]

I have written a program in C++ that inputs 3 files that describes a logical (non-sequential if matters) and user in simulation file tells which values to change (Just like ModelSim). I was able to ...
-4
votes
0answers
40 views

Program on cricket scoreboard [closed]

why is the following code not giving results and how to get results? I needed to post whole code because it would be difficult for people to understand the problem without whole code.whenever I run ...
2
votes
1answer
139 views

Insertion sorting Algorithm comparison

I recently came across sorting techniques and of particular, 'insertion sorting'. Although the logic and method is fairly understandable, the actual function seemed a bit complex (given below). ...
-2
votes
0answers
61 views

What are the return values for functions in Google's style guide

I am interested in learning C++ in greater depth by coding algorithms from a theoretical computer science book I am using as a text. As I code the different algorithms, I would like to make my own ...
1
vote
1answer
121 views

C++ Template Metaprogramming and Call By Need Evaluation

I recently wrote a fairly complex C++ meta function that boils down to: template <size_t N, typename val> struct Rec { using type = typename std::conditional<N == 0, val, ...
3
votes
3answers
475 views

Should I try it straight or should I first check if it can be done?

I have a set of items, and each item in the set must be unique. Item are composed from multiple properties and each property of each item can be changed. But after each change every item in the set ...
4
votes
1answer
263 views

What is the status of @ and $ characters in C++?

C++ syntax uses almost all printable ASCII characters and some of them in several contexts. Only two unused are @ and $ characters. Why they are not used? Are they reserved for some "meta" purpose?
3
votes
4answers
367 views

Are `switch` statements generally used wrong? [closed]

I see most developers using switch statements with breaks in each and every case. Is this usage of switch statements inappropriate since a simple set of if-else statements would suffice? Is it OK for ...
3
votes
0answers
207 views

How do you pronounce 'char' keyword? [closed]

So, with the possibility of this question being closed due to being non-productive as in the case of other pronunciation questions, I take the risk and ask it just because i have heard it said both ...
-1
votes
0answers
59 views

C++ segmentation fault class with pointer variable [migrated]

[Edited post, based on previous answers and comments. I have tried several strategies, none of which have worked.] I have a class D, with a member variable of class type E. E has two subclasses, E1 ...
1
vote
2answers
82 views

Class as resource handle & Bad Copy

I am reading Bjarne Stroustrup's book titled "A tour of C++". The following section is confusing to me: When a class is a resource handle – that is, when the class is responsible for an object ...
-1
votes
1answer
58 views

What are some hashmaps we can easily implement? [duplicate]

At many places, I read that we can use HashMap here for O(1) search. Actually, I want to ask how I can implement easy hashmaps which can satisfy this property. Can anyone tell few hashmaps including ...
1
vote
1answer
102 views

Constructor vs casting operator

I'm programming a library (so I have complete access to all the mentioned classes). Two classes (A and B) are essentially the same and differ only by their implementation, so they can be easily ...
4
votes
1answer
171 views

Designing interfaces to hardware

I am writing a library in C++ that is used by customers to interface with hardware. There are many different devices that I need to support. For the sake of simplicity, assume I have 2 Widgets, ...
8
votes
5answers
790 views

How to structure a loop that repeats until success and handles failures

I am a self-taught programmer. I started programming about 1.5 years ago. Now I have started to have programming classes in school. We have had programming classes for 1/2 year and will have another ...
9
votes
7answers
924 views

Will a profound knowledge of C++ help you in learning other languages faster/easier? [closed]

Is there a possibility that someone who has learned all the key aspects of C++ and knows the fundamentals of the language very well, will learn other languages (such as, Python, Perl, Java) faster and ...
-2
votes
2answers
344 views

What is the simplest and universal algorithm for parsing C++ code? [closed]

I need to do some project specific automatic checking of source codes written in C++ Limitations: Algorithm and its implementation should be simple, easily maintainable, extendable and ...
3
votes
2answers
187 views

Is it always safe to shift bool values?

I stumbled about a Cppcheck warning (an inconclusive one), that I mistakenly used & instead of &&: /// @param code identifies the command. Only the lower 16 bits of are being processed ...
0
votes
3answers
54 views

Defining resource allocation in method documentation

I want to write a library with "no resource leak guarantee" feature. So I shall know whether each method allocates any resource or not. It may change the code. For example: void foo() { ...
4
votes
2answers
210 views

Needs (in principle) C++ parenthesis around if statement condition?

In current C++ when body of if statements contain only one command then: Parenthesis around if condition are mandatory but block are optional. So, both examples are OK: if ( condition ) { return 0; ...
2
votes
2answers
146 views

Use of raw pointer of std::vector

I am currently maintaining a code that makes liberal use of raw pointers where std::vector would be a better option. Worse, these pointers are not always properly handled (when run using Intel ...
3
votes
2answers
168 views

How to deal with historic exception specifications in maintained C++ code

Today, I discovered a few exception specifications in legacy code I've to maintain, when Cppcheck 1.68 ([Inconclusive] but correctly) pointed out that the specified exceptions are not handled in ...
0
votes
0answers
6 views

count even length words in vectors [migrated]

I have 2 problems. 1) cout << v_setir.capacity(); is not returns the correct number. 2) I want to count of the words which lengths are even. and I should do it with vectors. Here is my codes: ...
0
votes
0answers
97 views

Requesting information regarding the use of MUI vs. the use of GetText for i18n/L10n of Windows desktop applications

I have spent the past two days investigating which technology I will use to support translations of text strings (as part of an overall internationalization migration) for an archaic (VC6) Windows ...
1
vote
1answer
137 views

Where should I place a typedef when used in method signatures in C++?

I'm using an Optional class quite similar to that of boost. For semantic reasons, I switched an attribute of the same (structured) type in some class definitions (and therefore also in method ...
-3
votes
0answers
12 views

Recursive solution for 3n+1 [migrated]

I just like to do simple recursion. For a number if it is even then it'll approach to (number/2) and if odd then to (3*number+1). How many time it'll occur to reach 1. for 10 10-> 5-> 16-> 8-> 4 ...
2
votes
3answers
3k views

Efficient algorithm to count number of substrings divisible by 3

Given a string of decimal digits, I have to find the number of all substrings divisible by 3 in the range L to R [both inclusive], where L & R are index[1-based] of the specified string string ...
0
votes
1answer
75 views

Is it possible to save and load a decorated object

I am wondering if there is an easy way to save and load a decorated object in c++ as i have never done file handling in C++ before. Currently the only object type I need to save is objects that ...
2
votes
1answer
75 views

How to make max-heap stable with counter and account for counter overflow?

Generally I need size-efficient data structure similar to std::priority_queue but stable (preserving order of insertion). By adding just 4 bytes to the object I could have 1 byte serving as priority ...