[Solved] C++ How can I delete -1 from my vector?

You’re accessing outside the vector. When you get to the last iteration of the for loop in bubbleSort(), numbers[i] is the last element of the vector, and numbers[i+1] is outside. This results in undefined behavior, and in your case it happens to access the -1 that you initially put in the vector and then popped … Read more

[Solved] how to erase several characters in a cell? [closed]

What are other patterns your data has? If it’s always “(B)” you can do sub(“\\(B\\)”, “”, df$code) #[1] “1234” “5678” “1234” “5678” “0123” Or if it could be any character do sub(“\\([A-Z]\\)”, “”, df$code) You could also extract only the numbers from Code sub(“.*?(\\d+).*”, “\\1”, df$code) You might want to wrap output of sub in … Read more

[Solved] C++: Using remove_if to filter vector on a condition

Below example demonstrates the usage of erase-remove_if. limit is captured by reference and can thus be modified outside the lambda: #include <vector> #include <algorithm> #include <iostream> int main() { std::vector<int> vec{0,1,2,3,4,5,6,7,8,9}; int size = vec.size(); for (int limit = 0; limit <= size; limit++) { vec.erase(std::remove_if(std::begin(vec), std::end(vec), [&limit](int i) { return i < limit; }), … Read more

[Solved] Getting a word or sub string from main string when char ‘\’ from RHS is found and then erase rest

To erase the part of a string, you have to find where is that part begins and ends. Finding somethig inside an std::string is very easy because the class have six buit-in methods for this (std::string::find_first_of, std::string::find_last_of, etc.). Here is a small example of how your problem can be solved: #include <iostream> #include <string> int … Read more