### Signed overflow in C++ and undefined behaviour (UB)

I’m wondering about the use of code like the following int result = 0; int factor = 1; for (…) { result = … factor *= 10; } return result; If the loop is iterated over n times, then factor is multiplied by 10 exactly n times. However, factor is only ever used after having…

Discover more

### Deleting a line from c++ file by giving a word

I have made a Quizlet code to save a word with its translation(in Russian) in csv file. So, the ‘add’ and ‘read’ functions work perfectly but I have been trying to make the ‘delete’ function remove a line when I give a substring of that line. update: I am trying to copy all the lines…

Discover more

### Algorithm Design: Best Way to Represent a 2D Grid, with Boundary Digits, in C++?

I like working on algorithms in my spare time to improve my algorithm design skills. I tackle Jane Street’s monthly puzzles as my ‘monthly challenge’. I’ve previously developed algorithms to solve their October Puzzle, and have solved their November puzzle by hand. I solved their November puzzle (Hooks #6) by hand, but only because I’m…

Discover more

### How to do multiplication for two 4-bit numbers treating them as polynomials in C++

I am simulating a mini AES encryption/decryption algorithm using C++. For this I need to multiply two 4-bit numbers while treating them as polynomials. It goes though some stages, that are, converting to polynomials, multiply the two polynomials, polynomial reduction to lower power if needed using a predefined irreducible polynomial. Then converting back to 4-bit…

Discover more

im having a problem that is asking for result from function, that is asking to read the file, the same function is doing good and only sends the last result that it got. that is my problem i need to send all answers that the function is getting. #include <iostream> #include <fstream> #include <iomanip> using…

Discover more

### How to represent polygons using c++

Found this question in google cache, really wish it hadn’t been deleted! (not my original question, but I have the same one…) I believe I can add some more background: “For my data structures class, we have to “implement a solution to the 2D Art Gallery Problem with a polygon representation”. This is more or…

Discover more

im having a problem that is asking for result, that is asking to read the file, the other function is doing good and only sends the last result that it got. Here the link for the problem im having. https://www.dropbox.com/sh/4baowle2badgj5i/AACwEvAenl2oN3Da1tG9-DRva?dl=0

Discover more

### C++ External Class in std::vector ( definition would be ill-formed )

I have built a class in an external library that I was hoping to use in other areas. However, when I try to use the class within an std::vector I get compile errors from ../../src/geom/geom.cpp:21: /usr/include/c++/4.8.2/ext/new_allocator.h: In instantiation of `void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& …) [with _Up = GenUtils::MeshNormalData; _Args = {const GenUtils::MeshNormalData&}; _Tp = GenUtils::MeshNormalData]`: /usr/include/c++/4.8.2/bits/alloc_traits.h:254:4:…

Discover more

### C++ Separate a string by spaces and commas

I am trying to read in a text file, separate the integer values by commas and white spaces ” ,” and add each individual integer excluding ” ,” to a vector of integers. The following code only prints the first value. What am I doing wrong? #include <iostream> #include <fstream> #include <string> #include <vector> #include…

Discover more

### C++ defninition/assignment syntax

Can anybody tell me what is happening in this Assignment statement? it was found in some code in a textbook. Somehow this is where val is initialized and without it it does not compile. INT_MAX is coming from The body of the code shouldn’t matter too much but I’ve never seens two values to the…

Discover more