Is there a built-in vector function in C++ to reverse a vector in place? Or do you just have to do it manually? 7 Answers 7
My understanding is that string is a member of the std namespace, so why does the following occur? #include <iostream> int main() { using namespace std; string myString =...
What are some really good reasons to ditch std::allocator in favor of a custom solution? Have you run across any situations where it was absolutely necessary for correctness, performance,...
Is it possible in C++ to replace part of a string with another string? Basically, I would like to do this: QString string("hello $name"); string.replace("$name", "Somename"); But I would...
I’m practicing using mulitple files and header files etc. So I have this project which takes two numbers and then adds them. Pretty simple. Here are my files: main.cpp...
I’ve got code that looks like this: for (std::list<item*>::iterator i=items.begin();i!=items.end();i++) { bool isActive = (*i)->update(); //if (!isActive) // items.remove(*i); //else other_code_involving(*i); } items.remove_if(CheckItemNotActive); I’d like remove inactive items immediately...
C++11 vectors have the new function emplace_back. Unlike push_back, which relies on compiler optimizations to avoid copies, emplace_back uses perfect forwarding to send the arguments directly to the constructor...
Someone brought this article to my attention that claims (I’m paraphrasing) the STL term is misused to refer to the entire C++ Standard Library instead of the parts that...
All I want to do is to check whether an element exists in the vector or not, so I can deal with each case. if ( item_present ) do_this();...
I’ve been told by others that writing using namespace std; in code is wrong, and that I should use std::cout and std::cin directly instead. Why is using namespace std;...