stl Questions

19

I would like to fill a vector<int> using std::fill, but instead of one value, the vector should contain numbers in increasing order after. I tried achieving this by iterating the third param...
Helvellyn asked 17/7, 2013 at 8:15

5

Solved

I need sample for traversing a list using C++.
Lawn asked 29/3, 2011 at 9:20

3

Solved

From my experience, it seems that the result of std::this_thread::get_id() is unique across process: ids are different from one process to another. Is this guaranteed by the standard?
Graminivorous asked 28/9, 2015 at 13:38

9

Solved

Would it be possible to initialize a vector array of strings? for example: static std::vector<std::string> v; //declared as a class member I used static just to initialize and fill it with s...
Psycholinguistics asked 24/11, 2010 at 16:10

21

Solved

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...
Redeemable asked 26/1, 2011 at 11:58

9

Solved

While using std::for_each algorithm how do I break when a certain condition is satisfied?
Jennings asked 17/4, 2009 at 12:30

16

Solved

Why does the C++ STL not provide any "tree" containers, and what's the best thing to use instead? I want to store a hierarchy of objects as a tree, rather than use a tree as a performance enhancem...
Tweedsmuir asked 15/10, 2008 at 18:52

6

Solved

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.
Minnesota asked 31/10, 2008 at 10:33

7

Solved

In a system where registered objects must have unique names, I want to use/include the object's this pointer in the name. I want the simplest way to create ??? where: std::string name = ???(this);...
Caper asked 21/10, 2011 at 13:31

7

I have a C++ STL map, which is a map of int and customType. The customType is a struct, which has string and a list of string, How can i serialize this to a file. sample struct: struct customType{ ...
Furnishings asked 14/11, 2011 at 12:15

4

Is it possible to evaluate std::optional::value_or(expr) argument in a lazy way, so the expr were calculated only in the case of having no value? If not, what would be a proper replacement?
Hydrated asked 5/8, 2018 at 15:12

27

Solved

I need to take a C++ vector with potentially a lot of elements, erase duplicates, and sort it. I currently have the below code, but it doesn't work. vec.erase( std::unique(vec.begin(), vec.end()...
Mirepoix asked 25/6, 2009 at 0:28

5

Solved

My team has encountered a deadlock that I suspect is a bug in the Windows implementation of SRW locks. The code below is a distilled version of real code. Here's the summary: Main thread acquires ...
Avow asked 1/3, 2024 at 23:9

16

Solved

How does one go about sorting a vector containing custom (i.e. user defined) objects. Probably, standard STL algorithm sort along with a predicate (a function or a function object) which would oper...
Chud asked 4/9, 2009 at 17:5

12

Solved

Perhaps this is a duplicate but I did not find anything searching: When erase(value) is called on std::multiset all elements with the value found are deleted. The only solution I could think of is:...
Carbonation asked 6/2, 2012 at 21:46

3

Solved

I am trying to implement an order statistics tree with using __gnu__pbds. I followed this code TREE_ORDER_STATISTICS But, I need this on a multiset. I was suggested to use a pair to implement this...
Cacomistle asked 29/5, 2017 at 8:43

8

Solved

If I have a structure like std::map<string, int> myMap; myMap["banana"] = 1; myMap["apple"] = 1; myMap["orange"] = 1; How can I access myMap[0]? I know that the...
Formerly asked 21/10, 2011 at 23:49

8

Solved

in c++, <stdexcept> has a base class for 'domain errors', std::domain_error. i don't understand under what circumstances i should throw a domain error in my code. all of the other exception b...
Bentham asked 13/3, 2009 at 0:41

3

Solved

I'm trying to use istringstream to split a simple string into a series of integers: #include <string> #include <iostream> #include <sstream> #include <vector> using namesp...
Forensics asked 2/3, 2011 at 14:16

5

Solved

I've started learning C++, so I don't know in my lack of knowledge/experience why something so seemingly simple to a rookie as what I'm about to describe isn't already in the STL. To add a vector t...
Chorale asked 16/6, 2011 at 1:38

6

In my program I need to delete an element from a priority queue that is not at the top. Can that be done? If not, please suggest a way to do so except creating your own heap.
Hereunto asked 19/10, 2013 at 15:6

8

Is it possible to convert UTF8 string in a std::string to std::wstring and vice versa in a platform independent manner? In a Windows application I would use MultiByteToWideChar and WideCharToMultiB...
Southeaster asked 29/9, 2008 at 12:3

5

Solved

Thinking of lambda expressions as 'syntactic sugar' for callable objects, can the unnamed underlying type be expressed? An example: struct gt { bool operator() (int l, int r) { return l > ...
Clef asked 5/10, 2010 at 20:4

5

Solved

I have the following erroneous code which I am trying to compile in VC2010, but I'm getting the error C2974 this only occurs when I include the lambda expression, so I'm guessing it has something t...
Threedecker asked 27/4, 2011 at 16:57

4

Solved

I'm using a vector of pointers to objects. These objects are derived from a base class, and are being dynamically allocated and stored. For example, I have something like: vector<Enemy*> En...
Bluepoint asked 1/9, 2009 at 7:58

© 2022 - 2025 — McMap. All rights reserved.