Why is it wrong to use std::auto_ptr with standard containers?
Why is it wrong to use std::auto_ptr<> with standard containers? 6 Answers 6
Why is it wrong to use std::auto_ptr<> with standard containers? 6 Answers 6
I want to examine the contents of a std::vector in GDB, how do I do it? Let’s say it’s a std::vector<int> for the sake of simplicity. 5 Answers 5
Is there a C++ Standard Template Library class that provides efficient string concatenation functionality, similar to C#’s StringBuilder or Java’s StringBuffer? 10 Answers 10
So, I wrote a bunch of code that accesses elements in an stl vector by index[], but now I need to copy just a chunk of the vector. It looks like vector.insert(pos, first, last) is the function I want… except I only have first and last as ints. Is there any nice way I can … Read more
I was looking at STL containers and trying to figure what they really are (i.e. the data structure used), and the deque stopped me: I thought at first that it was a double linked list, which would allow insertion and deletion from both ends in constant time, but I am troubled by the promise made … Read more
I’ve always thought it’s the general wisdom that std::vector is “implemented as an array,” blah blah blah. Today I went down and tested it, and it seems to be not so: Here’s some test results: UseArray completed in 2.619 seconds UseVector completed in 9.284 seconds UseVectorPushBack completed in 14.669 seconds The whole thing completed in … Read more
The question is how to convert wstring to string? I have next example : #include <string> #include <iostream> int main() { std::wstring ws = L”Hello”; std::string s( ws.begin(), ws.end() ); //std::cout <<“std::string = “<<s<<std::endl; std::wcout<<“std::wstring = “<<ws<<std::endl; std::cout <<“std::string = “<<s<<std::endl; } the output with commented out line is : std::string = Hello std::wstring = … Read more
What is the preferred way to remove spaces from a string in C++? I could loop through all the characters and build a new string, but is there a better way? 19 Answers 19
Using C++, and hopefully the standard library, I want to sort a sequence of samples in ascending order, but I also want to remember the original indexes of the new samples. For example, I have a set, or vector, or matrix of samples A : [5, 2, 1, 4, 3]. I want to sort these … Read more
What is wrong with this program? #include <memory> #include <vector> int main() { std::vector<std::unique_ptr<int>> vec; int x(1); std::unique_ptr<int> ptr2x(&x); vec.push_back(ptr2x); //This tiny command has a vicious error. return 0; } The error: In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/mingw32/bits/c++allocator.h:34:0, from c:\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/bits/allocator.h:48, from c:\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/memory:64, from main.cpp:6: c:\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/bits/unique_ptr.h: In member function ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Tp*, const _Tp&) [with _Tp = std::unique_ptr<int>, … Read more