General C++ Programming - May 2020

Accessing memory error
 
Hello, I am writing a program and it is compiled without any error. However, when I run that program, it is showing the error below. terminate called a...
[4 replies] Last: getFriendlyPose() is being called in an infinite loop. Is it allocatin... (by dutch)
i have two text files which contain integer type data i want to perform bubble sort on them.
 
#include <iostream> using namespace std; #include <fstream> #include <string> int main(){ const int require=15; const int require2=100000 ; int count;...
[1 reply] : You should edit your post to add code tags so that your code retains i... (by dutch)
Help with prime number code C++ (1,2)
 
Hey everyone. I am having trouble with my code and I do not understand what is going on. I wrote a code where I enter a number and it will tell me if it is a pr...
[28 replies] Last: I'm not the op. I just been playing around with it. @dhayden.... thi... (by markyrocks)
Storing data in Vector of Struct
 
Hello, I am writing a program using ROS Workspace. There is a structure of data and which is converted to std::vector in somewhere of the codes. I am trying to...
[7 replies] Last: As far as I can tell, that will compile, but is that really what you w... (by helios)
std::function
 
Why does std::function require that its function object be copy constructable? I wrote a custom version of std::function via my own type erasure classes the oth...
[1 reply] : https://quuxplusone.github.io/blog/2019/03/27/design-space-for-std-fun... (by dutch)
No Output, where is the problem?
 
DISCLAIMER: I don't want somebody to solve this for me, I just need someone to look the code over and let me know either where I went wrong (during file input,...
[1 reply] : Some points. 1. Writing 120 lines all in a single function isn't good... (by salem c)
by frek
C++ move semantics
 
Hello all, Do you, please, agree with the text below? • We refer to traditional C++ references (the single-ampersand one) as lvalue references. Modern C++ ...
[3 replies] Last: I also read about return value optimization on the Web. But I think w... (by TheToaster)
A lambda with a dangling reference...
 
Hi, I have a lambda with a dangling reference (i.e. it captures by reference a number passed by value, i_ below): template <typename T> auto f1(T i_)...
[3 replies] Last: it captures by reference because it has [&] in the lambda.. (by JUANDENT)
by volang
IOCP Threadpool
 
From microsoft: "When a process creates an I/O completion port, the system creates an associated queue object for requests whose sole purpose is to service the...
[no replies]
Initialize pair constructor
 
Good evening to everyone, I'm learning how to use pair function, and my compiler says to me that i'm making an error because my pair contructor is initialize...
[10 replies] Last: Okay i get it, i'll try to solve it thank you! (by AlessandroTZ)
Infinite Loop?
 
string Automaton :: generation_to_string(const vector<int>& gen, size_t width){ if(width%2 ==0) return ""; string ans = ""; for(auto u:gen){ if(!u) ...
[5 replies] Last: @doug4 The issue seems to be that (width-gen.size())/2; can be negativ... (by aceadams)
How do I stop getting it to output 1
 
Hi this is my code: #include <iostream> using namespace std; void primeNumbers (int a, int b) { int flag, i; while (a <= b) { flag = 0;...
[2 replies] Last: Why don't you break the tasks in 2 parts. One function that checks if ... (by Thomas1965)
by Vycues
Mouse moving a picture box in C++ GUI
 
I am trying to move a picture box and drag it to a different location on the form using the left button pushed down on the mouse. The code below moves the pictu...
[2 replies] Last: Thank you so much. it works now. (by Vycues)
Huffman
 
My code is #include <iostream> #include <map> #include <fstream> struct huffman_node { int priority; char letter = 0; // Use null char for internal nodes, ...
[8 replies] Last: There are a number of problems. freq_dist_from_file() is recursive, b... (by kbw)
how to get the current executable directory?
 
Hi, filesystem::current_path() returns current working directory but I need the directory from which the executing program was launched. Is there a way? R...
[6 replies] Last: GetModuleFileName works!! Thanks!! Juan (by JUANDENT)
Unique_ptr with templates
 
Goodmorning to everyone. I'm trying to use smart_pointers for representing template variables into classes. Here an example: #include <iostream> #include <m...
[2 replies] Last: I'm so sorry, i've just noticed an error in the rest of my program tha... (by AlessandroTZ)
How to change my code?
 
Hi everyone, I’m quite green in programming but I want to know how to change my code that generates ARRAY and divides every element by RAND_MAX number into co...
[7 replies] Last: @helios, Thanks for the info. Now I know. (by doug4)
by frek
Temp objects
 
Hi all, A quick question: using namespace std; double t = 5; double test() { return t; } int main() { test() = 14; cout << t << '\n'; cin.get(); r...
[6 replies] Last: Depends on your system, but here's one set of answers: https://docs.mi... (by Repeater)
by volang
new unique char inside each object
 
struct ClientInfo { WSABUF Buffer; ClientInfo() { Buffer.buf = new char ; Buffer.len = 2000; } }; Every new object that is created from this s...
[5 replies] Last: You're copying an object into another, where the class of both contain... (by helios)
Help with implementing Dijkstra's Algorithm
 
Hello, I am having trouble implementing pathfinding in my program. I am using coordinate based vertexes along with edges holding the coordinates of the related...
[5 replies] Last: I managed to get it implemented by going back after my vertexes are cr... (by tigerking)
May 2020 Pages: 123... 9
  Archived months: [apr2020] [jun2020]

This is an archived page. To post a new message, go to the current page.