Click here to Skip to main content
15,888,401 members
Everything / STL

STL

STL

Great Reads

by Thorsten Ottosen
Are you tired of filling data manually into STL containers? With the Initialization Library it gets a lot easier.
by Shmuel Zang
This article shows how we can implement a thread-safe events (similar to .NET events) mechanism using the standard C++ library.
by JadBenAutho
Efficient and standalone library for NTP server/client utilizing pure C++
by Michael Dunn
Create custom tasks in your app's jump list on Windows 7

Latest Articles

by JadBenAutho
Efficient and standalone library for NTP server/client utilizing pure C++
by Vadim Stadnik
Simple and useful alternative to traditional memory pool
by Steffen Ploetz
Is LINQ the right technology for processing large amounts of data in runtime-relevant environments?
by honey the codewitch
std::chrono doesn't work on the Teensy? Oh no! Here's how to fix it.

All Articles

Sort by Updated

STL 

2 Mar 2024 by JadBenAutho
Efficient and standalone library for NTP server/client utilizing pure C++
2 Oct 2023 by sahil ajmeri 2022
I have STL file where I want to apply 4x4 matrix. The matrix I want to apply is: [[2.7282, 0, 0, 0], [0, 4.0014, 0, 0], [0, 0, 1, 0], [0,�0,�0,�1]] Here is my STL file: https://we.tl/t-v6SHprAeUZ[^] I have used Python code to apply matrix...
20 May 2023 by steveb
clear() in STL containers does not re-shrink the allocated storage. If you call capacity(), you will get the real allocated storage size on an emptied container. If you must release the allocated storage you would need to call swap() function...
20 May 2023 by Mathi Prasad
Hi Team, i have tries to analysis the memcheck throughout while insertion of new elements in list, map, vector anything. am getting high memory utilization at particular PID in linux. After the list object as clearing, still am seeing the same...
18 May 2023 by CPallini
See, for instance: https://stackoverflow.com/questions/12050777/how-to-return-memory-from-process-to-the-os[^]
18 May 2023 by OriginalGriff
What did you expect? You are creating 10,000,000 streams, and adding them all to a list: list l1; for(int i=0;i
4 Apr 2023 by Richard MacCutchan
Or you could go to Containers library - cppreference.com[^].
4 Apr 2023 by mathiv327
Hi friends, need website for STL containers about i needs to learn the memory allocation for different containers. please share that wenb site. What I have tried: have tried and learn some of web site but no use of it
4 Apr 2023 by OriginalGriff
Start with Google: website for STL containers - Google Search[^]
20 Mar 2023 by mathiv327
Hi friends, am getting core while dereference the list iterator. Hence, i required condition for not executing this lines. I have tried using list empty and size also. but it was no use of it. #include #include using...
20 Mar 2023 by Daniel Pfeffer
it4 points to the beginning of the list 'itr2->second'. You then check whether 'itr2->second' is empty, and if it is, you attempt to dereference it4. If 'itr2->second' is empty, it4 cannot be dereferenced. Rewrite your code to invert the...
6 Feb 2023 by Vadim Stadnik
Simple and useful alternative to traditional memory pool
4 Jan 2023 by Yago.bg.
Original Subject line: Como generar un .gcode con programación para impresión 3D Necesito poder generar un .gcode a partir de un STL desde algún lenguaje de programación. Para poder imprimir en Impresoras 3D. Google translate: I need to be...
4 Jan 2023 by OriginalGriff
Ultimaker Cura is a commercial product (and a good one, I use it myself for FDM printing), so the libraries are almost certainly Ultimaker IP and not in the public domain. To acquire them, you would have to talk directly to Ultimaker and ask them...
15 Nov 2022 by Steffen Ploetz
Is LINQ the right technology for processing large amounts of data in runtime-relevant environments?
24 Aug 2022 by honey the codewitch
std::chrono doesn't work on the Teensy? Oh no! Here's how to fix it.
7 Jul 2022 by Greg Utas
Analogous functions, subtle differences, multiple compilers...
22 Jun 2022 by Stephane Capo
C++ optimization for map using string key among others
22 May 2022 by dj4400
Hi I am writing an app. in c++ that manages a list of polygons Each polygon contains a list of points The point is defined as follows: typedef struct { float x; float y; float z; }PolygonPoint; The Polygon is defined as follows: typedef...
22 May 2022 by 0x01AA
Same here, ran the code without problems on https://www.onlinegdb.com/online_c++_compiler[^] /****************************************************************************** Online C++ Compiler. ...
22 May 2022 by Richard MacCutchan
I just ran this code and it worked OK: std::list Polygons; //I declare a polygon: PolygonData stPol; stPol.id = 1; strcpy(stPol.name, "Foo"); PolygonPoint ppt; ppt.x = 1; ppt.y = 1; ppt.z = 1; stPol.PointsList.push_back(ppt); ...
20 Jul 2021 by Axter
A smart pointer which acts like a reference variable
9 Jun 2021 by Member 12621273
I have a vector like this : vector > > vI want to access all the three elements . How can i do that through iterator?What I have tried:I looked for the possible answers on the internet but cannot get any satisfactory answer. I tried iterator like this...
9 Jun 2021 by merano99
// I have a vector like this : vector > > v; // I want to access all the three elements.How can i do that through iterator ? pair p1(1,2); pair > p2(3, p1); v.push_back(p2); ...
9 Jun 2021 by Member 15239417
you do like this, vector > > v; INSERION OF VALUES: v.push_back(make_pair(a, make_pair(b, c))); ACCESSING VALUES: a = v[i].first; b = v[i].second.first; c = v[i].second.second;
2 Jun 2021 by Steffen Ploetz
Why replacing std::vector with std::set sped up my UndoRedoAction class by about 20x
27 May 2021 by John M. Dlugosz
Using swap etc. from generic code must be done properly. Here’s how to fix it for good.
14 Apr 2021 by Aleh Baradzenka
The control representing a regular ToolBar in the form of a tree of command buttons
24 Jan 2021 by CPallini
Here you are, but... Are you really sure you want this? #include #include using namespace std; struct Test { string name; int id; }; struct Test1 { int errCode; string errName; map mapOfTest; }; struct...
24 Jan 2021 by Member 15025528
I have below code. I have inserted the data in the structures. I need to access the first value of mapOfTest using mapOfTest2. #include #include using namespace std; typedef struct { string name; int id; }Test; ...
24 Jan 2021 by Richard MacCutchan
The variable mapOfTest2 contains an entry that points to a Test2 object. That in turn has an entry that points to a Test1 object. The Test1 object contains the mapOfTest map. So following the links will get you to that map and give access to its...
23 Dec 2020 by Haakon S.
Hi. What does it mean when something is deprecated in STL. I understand that it is not recommended for use, but will it not be functioning anymore? I have previously used strstream in my application, pre 2012. In Visual Studio 2019 it does not...
23 Dec 2020 by Richard MacCutchan
This is referring to your question at std:strstream does not work - C / C++ / MFC Discussion Boards[^]. When a method or class is deprecated, it means that it is not recommended and may be removed in the future. So if you have such references in...
11 Dec 2020 by honey the codewitch
Apparently I'm getting rusty. I need to find a way to have an unordered_map reference a struct using just its forward declaration, but I want STL to handle allocation and cleanup like normal. See the code for a concrete example of what I want. ...
11 Dec 2020 by steveb
Forward declarations work only for pointers and references. Depending which compiler you using, the "map_value" is an incomplete type at the point where you declared it inside the struct map_value body. I beleive it probably should be: struct...
10 Dec 2020 by honey the codewitch
Try mv.value.insert(std::make_pair("test",std::unique_ptr(pmv2))). std::make_unique is really simply... dynamic allocation (with new) following by constructing a std::unique_ptr to hold the pointer. The constructor is explicit so it...
18 Nov 2020 by Vadim Stadnik
Discussion of simple variants of Voronoi diagram
11 Nov 2020 by Member 14849246
I was solving a problem of arrray of finding the pivot index of the array, ie. left sum and right sum of that element should be equal I used accumulate in stl but i wonder if interviewer ask the time complexity of the accumulate fx then i shoul...
11 Nov 2020 by Rick York
Did your search find this page : accumulate - C++ Reference[^] ?
18 Oct 2020 by Espen Harlinn
An introduction to C++ 20 concepts
17 Aug 2020 by Espen Harlinn
Ranges is coming to C++, and the Range-v3 library was the basis for the proposal to add range support to the C++ standard library
4 Jun 2020 by Maciej Los
I'd suggest to start by reading tutorials: C++ Classes and Objects - GeeksforGeeks[^] Arrays in C/C++ - GeeksforGeeks[^] Inheritance in C++ - GeeksforGeeks[^] Polymorphism in C++ - GeeksforGeeks[^] Tip: under the third link, you'll find sample...
4 Jun 2020 by Patrice T
You show no attempt to solve the problem yourself, you have no question, your main effort is pasting the requirement, you just want us to do your HomeWork. We do not do your HomeWork. HomeWork is not set to test your skills at begging other...
4 Jun 2020 by CPallini
Find a suitable data structure. That is find for each car what are the relevent properties. Find a way to store to such a (an array of) structure (and then read back from) a file. Eventually implement all the required functionalities. If you are...
4 Jun 2020 by OriginalGriff
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us...
26 May 2020 by stefan stammberger
A novel allocator implementation for managing huge sets of data in STL's std:: containers for Windows operating systems
6 May 2020 by Arthur V. Ratz
In this article, I’d like to introduce the modern code in C++11, implementing the parallel three-way quicksort, which is asymptotically faster and more efficient than the famous heapsort and mergesort algorithms.
19 Mar 2020 by Nikola M. Živković
In this article I tried to sum up what has been my greatest challenges and things that I had to accept and change about myself after becoming Team Lead.
13 Jan 2020 by Dominik Reichl
KeePass is a free, open source, light-weight and easy-to-use password manager.
19 Dec 2019 by Edwig Huisman
CString only projects can convert to STL std::string
3 Dec 2019 by thoughts-on-coding
Matrices are a key concept in solving linear equation systems. Efficient implementations of matrices are not only considering computation complexity but also space complexity of the matrix data.
23 Nov 2019 by Zhaohui Xing (Joey)
Swift classes for algorithm, including single linked list class, stack class, queue class
29 Oct 2019 by SelfTask
What is an easy game to code in C++ that uses with STL's hashes, sets, and maps data structures? What I have tried: I was thinking War or Blackjack but what's a better idea outside card games?
29 Oct 2019 by John M. Dlugosz
I recall this series of videos on YouTube: Let's make 16 games in C++/SFML! - YouTube[^] There is also this series from OneLoneCoder: Code-It-Yourself! - YouTube[^]
22 Sep 2019 by Rodrigo Cesar de Freitas Dias
Introducing WinLamb, a modern C++11 object-oriented library to write native Windows programs
9 Apr 2019 by Martin Vorbrodt
Multi-hashing
21 Mar 2019 by thoughts-on-coding
How can we share and increase software development knowledge in a heterogeneous team? Weekly Knowledge Candy
21 Mar 2019 by Martin Vorbrodt
Parsing Command Line Options
14 Mar 2019 by Martin Vorbrodt
How to serialize data to XML
14 Mar 2019 by Martin Vorbrodt
Parallel STL
14 Mar 2019 by thoughts-on-coding
Using pointer to members is sometimes a mighty feature of C++. In this post you see a way of how to use them in STL algorithms.
14 Mar 2019 by thoughts-on-coding
Implementing the implicit Euler-Method with STL
19 Feb 2019 by steveb
A simple Sci-Fi plot compiler
4 Feb 2019 by Timothy Hogan
In my embedded program I have a 5 "soft keys" arranged with a LCD screen. What I would like is to have a pointer for each button that can point to free functions or member functions and can take any signature. This pointer will need to be redirected to other functions at runtime. Obviously I...
4 Feb 2019 by CPallini
As far as know, without considering 'dirty hacks' (trying to defeat the strongly typed nature of C++), you cannot do that. I would use just one function signature and then adapt all of my functions to comply with it. Within this approach you might possibly find useful std::function[^].
4 Feb 2019 by Richard MacCutchan
There is no easy way around this, since the compiler needs to check the call matches the function signature. You could define each function to take a void* as its only parameter and then cast it internally to the correct structure. Or you could use the varargs option where you pass one fixed...
25 Nov 2018 by Bartlomiej Filipek
What performance can we get from C++17 parallel algorithms?
26 Sep 2018 by steffi123
I am able to typecast reference of vector to reference of vector whereas I am unable to typecast vector to vector. I am getting the error C2440: 'reinterpret_cast' : cannot convert from 'std::vector' to 'std::vector' why? And I am able to typecast void* to...
26 Sep 2018 by Rick York
One thing I find helpful in these situations is to use type definitions. Here are a couple types I would define in this situation :typedef struct Foo * pFoo; typedef std::vector vecpfoo; Then I would adjust your functions to this :void reportFoo( int index, pFoo pf ) { cin
25 Sep 2018 by KarstenK
Type casting can lead to strange errors when done wrong, so it is better to avoid this or handle it with greatest care. So avoid type casting to void* because the programmer and the compiler are loosing precious informations about the objects. Any up cast is leading to different handling of...
25 Sep 2018 by CPallini
The reason is simple: reinterpret_cast only works with pointers (this is the short answer, for the detailed one, feel free to read the documentation: reinterpret_cast conversion - cppreference.com[^]).
24 Sep 2018 by steffi123
Hi, How to pass std::vector * as std::vector* to a function? The function declaration is void SetDataReferences(std::vector* pVector); if I pass std::vector * as std::vector* I am getting below error error C2664: 'SetDataReferences' : cannot...
24 Sep 2018 by KarstenK
The alternative is very clear: creating and passing the parameter in the right type. You should take this warning very serious because it screams for a coding flaw. //TODO: Change the creation code of input parameter
24 Sep 2018 by CPallini
Provided you are sure the vector you are passing actually contains pointer to valid MyStruct instances, a reinterpret_cast[^] would do the trick. Try, for instance: #include #include using namespace std; struct Foo { string s; int i; }; void reportFooVector( vector...
13 Aug 2018 by Shmuel Zang
This article shows how we can implement a thread-safe events (similar to .NET events) mechanism using the standard C++ library.
5 Jun 2018 by Shao Voon Wong
An article on finding combinations
4 Apr 2018 by Orjan Westin
Function and supporting class to write a memory dump with hex values and characters to an output stream
26 Mar 2018 by Vishal Bhatia0112
I have a Vector of structure that is sorted on based of a variable. For ex: struct Client { string name; int sm_index; int client_id; int user_id; } Sorted on based of sm_index. How can i find and fetch the data of that struture whose sm_index matches our target structure. ...
26 Mar 2018 by Rick York
Here's an example of how to use binary_search : bool Compare( const Client& lhs, const Client& rhs ) { return ( lhs.client_id clientVec ) { return binary_search( clientVec.begin(), clientVec.end(),...
25 Mar 2018 by KarstenK
Thats sounds poor, because iteration is one main standout feature of the vector container class. If your vector is sorted I would suggest the faster binary search but I think that you may consider this in a later stage of your project.
20 Mar 2018 by Rick York
The right and left parameters would be of type LeftOp and RightOp and those are of type Matrix. You can see this by looking at the template code in the listing. Here are two snippets : template class EtMatrixAdd { public: ...
20 Mar 2018 by Member 13737179
Hi, I am new to expression template programming, I went through this tutorial. It's pretty good I understand things a bit but not able to replicate code to working one. Can someone help ? What I did -> From [listing 3] I saved it as matrix.h file but don't know how can I make a new matrix...
29 Jan 2018 by saide_a
yesterday I found out something first when I use cout for printing my structure it works Okey. but when I want to read and write from file this happens, this problem occurs only with use of stack and queue. At second, I used headers for serialization in main function before, but when I use that...
27 Jan 2018 by saide_a
I am new in using boost serialization library. I want to save and load data to and from STL structures using text_iarchive and text_oarchive. I used bellow code for that: mystruct test; test.initial(); { std::ofstream ofs("filename.dat"); boost::archive::text_oarchive ar(ofs); ar &...
15 Dec 2017 by trident99
The HPC Template Library is a supplement to the Standard Template Library providing threadsafe containers.
7 Dec 2017 by draculamx
std::string f; f.append(0,2); f[0]=2; f[1]=1; //f="cd"; std::string s; s.append(0,5); s[0]=1; s[1]=2; s[2]=1; s[3]=3; s[4]=1; //s="abcde"; unsigned int pp=0; pp=s.find(f); this code work fine in Visual Studio 2008 sp1,operation system is Win7 64Bit sp1 but in C++ Builder...
7 Dec 2017 by draculamx
s.append(0,5) //wrong s.append(5,0) //right sorry for waste your time......
6 Dec 2017 by draculamx
OK,someone told me a solution change "f.append(0,2); s.append(0,5)" to "f.resize(2); s.resize(5)" then it's work fine!!
6 Dec 2017 by draculamx
the std:string not only use for charactors,in fact it can store data like BYTE each element. so ,why "abcde" work,but "0x1,0x2,0x3" not work ?? and these code work in Visual Studio 2008 fine.....
6 Dec 2017 by Rick York
I think you could write : f[0] = 'c'; f[1] = 'd'; or f[0] = 'a' + 2; f[1] = 'a' + 3;
21 Nov 2017 by IAmJoshChang
How to create a VR first person shooter IV - Game over panels
22 Oct 2017 by IAmJoshChang
How to stop the time score system when the game is over
10 Oct 2017 by Member 11033237
please help me coding (in language C)quine mcCluskey's method for solving upto 8,9 or 10 variables whose minterms are to be generated automatically, only the no. of minterms, no.of variables and vectors of minterms are user given
25 Sep 2017 by IAmJoshChang
How to run your Libgdx game on your desktop
18 Sep 2017 by David Wincelberg
Sort by month name in database tables, filenames or strings
16 Aug 2017 by Alasdair Craig
A C++ implementation of a published algorithm for computing the concave hull using a k-nearest neighbour approach.
24 Jul 2017 by Mark Danniel
I wrote a MFC application program in VS2010 IDE.I used some STL containers such as vector,map ,etc.But after ruuning my program,the program crashed.The error message said "map/set iterator not dereferencable!".So what shoud I do can find where the code caused the crash?How to locate the...
24 Jul 2017 by OriginalGriff
Use the debugger. Run your app in the debugger - it's pretty simple, google will find you instructions - and when it crashes, use the stack trace to locate the function in your code that made it crash. Put a breakpoint at the top of the function, and your your app again. This time, it will stop...