Relative Content

Tag Archive for c++vector

Print floats of a vector and respective quantity of each

I’ve been trying to code a program in C that, given a float vector, determines how many of each number there are, and then, prints each number and their respective frequency. This is an exercise from my college (computer science course). In total, I must have spent like 3 hours trying to think about a solution and I just can’t think. I’m certain this is trivial, though. But I’m stupid.

Change index of element in C++ std::vector

I am trying to change the position of an element in an array. The way I am currently doing this is by inserting the element into its new index, and then erasing the old element at the old index. Is there a better way to do this?

Erasing an element from a vector in C++

I’m trying to remove the negative elements from a vector (lesser than 0) using the below code, however whenever a vector has a negative as its last element I’m getting an error(Segmentation fault)