Questions tagged [stl]

1

votes
1

answer
60

Views

How to access map of set of pairs elements?

#include #include #include #include int main() { std::mapmap1; for(int i = 0; i != 3; ++i) map1[i].insert({i+1,i+2}); for(auto i : map1){ std::cout
Aditya Ishan
1

votes
1

answer
89

Views

Hash & EqualTo functions for unordered_set<BSTR>

In a code, that inserts the Windows style OLE strings (BSTR's) into the good ol' STL container - the unordered_map, I declared the unordered_set, like this: unordered_set usetBstr; expecting BSTR strings to act like wstrings. Everything seemed to work fine, until one day a BSTR with a zero wchar in...
George Robinson
1

votes
2

answer
62

Views

How can I remove an item from a set in C++ without deleting it?

Using std::set in C++, the only way I can find to remove an item from a set is to use the erase method. This deletes the item in question, which I don't want to happen. The only way I can think of to remove an item from a set without deleting it would be to create a new set and add all the items of...
skrooms
3

votes
2

answer
52

Views

Why is not the condition *First1 == * First2 ?? (C++ STL includes function implement)

I'm a student studying STL C++ and have a simple Question. I was wondering while learning how to implement the includes function in the algorithm library. See this code (this code from https://en.cppreference.com/w/cpp/algorithm/includes) template bool includes(InputIt1 first1, InputIt1 last1, Inpu...
GE LO
1

votes
1

answer
2.6k

Views

R: Deseasonalizing a time series

We can use following code to plot and decompose a time series in R: # Monthly Airline Passenger Numbers 1949-1960 data(AirPassengers) data = data.frame(AirPassengers) data #Transform to time series ts.data1 = ts(data=as.vector(t(data['AirPassengers'])), start = c(1949), end = c(1960), frequency=12)...
Rnaldinho
1

votes
1

answer
1.2k

Views

Adding dynamic entries in c++ map

I know this may be a silly question but I'm new to c++ and I could not find answer to my question. I'm using STL std::map to maintain a list of subscriptions and their remote server IPs and PORTs. The number of servers may vary from subscription to subscription. If the number of server is 2 for a s...
C_user5
1

votes
1

answer
109

Views

Array with fixed size at runtime

I know I can use std::array to a have an array of the type Type and a size, which is fix at compile time. Furthermore, std::vector can be used, if the size is not fixed at compile time, but given at runtime. Is there an std container, which can be set at runtime to a certain size and this size is th...
schorsch312
1

votes
3

answer
132

Views

c++ STL min_element

I want to find the minimum element in an array, but if the minimum element appears more than once, then I want the last occurrence of the element. I used std::min_element() with my comp() function. vector::iterator it=min_element(input.begin(), input.end(),comp); cout
Rohit Pandit
1

votes
1

answer
50

Views

std::min element weird behavior when class is wrapped by shared_ptr

I've had a long debugging session (6 hours or more). I was debugging my A* algorithm implementation. After checking every possibility, after adding logging, debugging step by step etc. I finally found the answer. Basically, it all boils down to one line, where I search for the minimum value in a vec...
dabljues
1

votes
3

answer
6.6k

Views

copy contents of vector into file

i have following code for copying content of vector into file #include #include #include #include #include using namespace std; void dump(vector& v){ ofstream out1('C\\Users\\datuashvili\\Desktop\\vector.txt'); if(!out1){ exit(1); } copy(v.begin(),v.end(),ostream_iterator(out1,' ')); } int main(){...
dato datuashvili
1

votes
1

answer
258

Views

How to convert Three.js to .stl files for 3D printing?

I found one page link: Convert Three.js to .stl for 3D printing? var exporter = new THREE.STLExporter(); var str = exporter.parse(scene); console.log(str); But when I'm using them, not export a stl file. How can I do then?
panda
1

votes
1

answer
361

Views

C# Dictionary to C++ std::map

I have a Dictionary variable in my C# file Rec.cs defined as: Dictionary pPrepDumpLoadList This pPrepDumpLoadList is filled with keys and values like following foreach (XElement element in root.Elements()) { PrepDumpLoadItem item = new PrepDumpLoadItem(); item.Name = element.Name.ToString(); strin...
Nick X Tsui
1

votes
3

answer
176

Views

Passing STL vector wrapped in shared_ptr [duplicate]

This question already has an answer here: Is it bad practice to allocate memory in a DLL and give a pointer to it to a client app? 10 answers I'm wondering about a situation where I'm trying to return a vector from DLL to .exe app. Compilers and settings for DLL and .exe app are the same. I know th...
drewpol
1

votes
0

answer
52

Views

c++ / Visual Studio 2010 / add just-constructed-element to list

I'm on a big C++/stl mystery with Visual Studio 2010 : I push back an object to a list, and when I access to it, I get partially un-initialized data. Here is a very minimalist sample of code that produce this behavior : #include #include #include using namespace std ; struct Foo { Foo ( int x , i...
Captain'Flam
1

votes
0

answer
167

Views

forecast package versions giving different result on loess time series

I am using forecast package on R Studio with R version 3.3.2. I am forecasting a time series with loess method (stl). Issue is when I run the same code on R version 3.4.1 the results are very different from what I got on version 3.3.2. Below is the section of code where I am facing issue. wcfit
Vikrant Verma
-1

votes
0

answer
15

Views

Unable to insert more than 28800 items to vector of vectors without buffer

I have such a code: template void Matrix::loadMatrix() { for (auto& item : matrix) { for (auto& nestedItem : item) { file >> nestedItem; } } } When I use this version I am able to insert to that matrix (which is std::vector>) only 28800 items. When I am using this version: template void Matrix::lo...
rrrrroo
1

votes
0

answer
124

Views

Is the prime number 532660159 somehow “connected” to the STL?

If you do a std::vector v = std::vector(); your vector is going to have a capacity equal to zero, fine. Now I have an API having a function having a std::vector reference parameter to which I pass a vector definied as above. And at debug, I see a capacity equal to ... 532660159. At the beginning I t...
1

votes
1

answer
232

Views

How does gdb print stl containers

How does GDB pretty print this container? const unordered_map map{{'hello', 1}, {'world', 2}}; (gdb) p map $1 = std::unordered_map with 2 elements = {['world'] = 2, ['hello'] = 1} How can I get this functionality for my custom container?
applewil
1

votes
1

answer
64

Views

Why is this regex wrong in the STL world? [duplicate]

This question is an exact duplicate of: Why this regex for parsing m3u doesn't work? 2 answers Why is this regex wrong in the STL world? (?
Malik Urac
1

votes
0

answer
97

Views

C++ store Class template objects with different specialization inside unique std collection

I have an Action class specialized through templates. I would like to store different specialization of Action types inside an unique std c++ collection (std::map, std::vector, etc...). Here the Action classes: #include #include #include template class Action { private: std::function function; pu...
Squerut
1

votes
0

answer
102

Views

int to std::vector<bool>

The ultimate goal of this is converting a 32-bit integer to an STL vector container of bool. Is it possible avoiding iterating through the number's bits? One way would be getting access to the raw pointer: void int2bin(int number){ // Initialize the vector std::vector container(32); // Get low level...
Mini Fridge
1

votes
2

answer
91

Views

C++ custom comparator not working MWE

I know there has been few posts about this already, so feel free to remove my post, but this code: #include #define tol 1e-9 using namespace std; int n; vector vec; struct comparator { bool operator () ( pair &a, pair &b ) { if ( fabs(a.first-b.first) < tol ) return a.second < b.second; return a.fi...
Ilonpilaaja
1

votes
1

answer
100

Views

Can I use member function of underlying container of priority_queue

As title, I created a priority_queue(default use vector as underlying container) p. Can I use vector's member function likep.push_back(a)or p.reserve(25) or even use for(auto i:p) {cout ' has no member named 'begin' etc. How should I do to if i want to use the function mentioned above, or they are j...
CodePurin
1

votes
2

answer
143

Views

c++ std regexp why not matched? [duplicate]

This question already has an answer here: Regex not working as expected with C++ regex_match 1 answer i wannna get keyword matching length but, always match count is zero why..? string text = 'sp_call('%1','%2','%a');'; std::regex regexp('%[0-9]'); std::smatch m; std::regex_match(text, m, regexp);...
Biz Chepp
1

votes
1

answer
64

Views

Inserting character after every nth element of a string (not using stringstream)

I've written a function that removes spaces and dashes from a string. It then inserts a space after every 3rd character. My question is can anybody suggest a different way to do this not using stringstream? #include #include #include #include using namespace std; string FormatString(string S) {...
arcoxia tom
1

votes
2

answer
104

Views

Cant find a specific key in my stl container map

Hi I have been racking my head over trying to make my iterator pointer find the specified key for the map stl container. The following project is for my parser excercise where we are given a file and the point is to parse through it and read each line by line. The file is supposed to be in the proj...
Enoch Thomas
1

votes
0

answer
64

Views

using vectors that hold unknown object types

I'm trying to use an std::vector where I don't know the type. I've been able to convert the vector and pass it to and from functions. But I can't figure out if it is possible to access the objects within the vector without knowing the object type. I do know that the objects will always be pointer...
Danny Diaz
1

votes
0

answer
202

Views

Simplygon import textures issue

it would be great if someone can help me. I'm trying to import a textured model from Blender to Simplygon 8. The problem is that all gone fine except that the textures are not imported on Simplygon so I can't optimize them. The model is exported to FBX, OBJ and STL but none of them import the textur...
1

votes
1

answer
45

Views

How to insert pairs into a map based on user input and then find the element associated with a key given by user?

The following code is not working if I add the part to find the element. Without that part, the 1st part of code is working to add and display elements of a stl::map #include #include #include using namespace std; int main() { int n, k, q; char *v; map m1; map::iterator it; cout > n; cout k; cin >>...
Jay S
1

votes
0

answer
59

Views

C++ standard library algorithms that require default constructibility

The book Elements of Programming by Alexander Stepanov emphasizes the use of 'regular types'. These types have various requirements, but one of those requirements is that the type is default constructible. Alexander Stepanov is the designer of the Standard Template Library (STL), and thus has been i...
David Stone
1

votes
0

answer
71

Views

C++ convert list element pointer to list iterator

I have a std::list where T has some member functions, specifically the constructor of T, that would like to let some other classes know about the T's address in the list. This is so the other classes can later remove that node / splice it into another list / etc. At construction the T doesn't yet ha...
schieghoven
1

votes
0

answer
57

Views

Using a map with a non-trivial key type

I have a trouble implementing a map with a non-trivial key type. Originally, I needed a map, which would use GUID type as the key: std::map Since compiler does not know how to compare GUIDs, I chose the following approach to resolve the problem. Let’s have a wrapper around GUID in the following ma...
Alex
1

votes
0

answer
61

Views

std::experimental in production code in visual c++?

What is the current status of using std::experimental namespace in production? We are using Visual C++ to design some C++ UWP Windows Runtime Components. Right now when we write async code we use create_async, create_task, ... It would be more elegant to use coroutines. But since they are in std::ex...
user10013079
1

votes
1

answer
379

Views

Removing a pair from a vector of pairs [duplicate]

This question already has an answer here: How do I erase an element from std::vector by index? 10 answers I have a vector of pairs std::vector lambda; I would like to remove the kth element, i.e lambda.erase(&lambda[k]); lambda.erase(lambda[k]); Both of these attempts throws a no matching function...
HMPARTICLE
1

votes
1

answer
43

Views

Class overloaded operator '<' is not called when inserting shared pointer to set of that objects

Consider program below: #include #include #include #include class Boo { public: using ShPtr = std::shared_ptr; bool operator < (const Boo& boo) const { std::cout
Adam Stepniak
1

votes
2

answer
18

Views

The list is not printing through the printList(), what i'm doing wrong here?

See my code below. #include #include #include #include using namespace std; // a global variable std::listmyList; void addToList(int max, int interval) { for (int i = 0; i < max; i++) { if( (i % interval) == 0) myList.push_back(i); } } void printList() { for (std::list::iterator itr = myList.beg...
Mahesh
1

votes
1

answer
75

Views

Error while init of C++ std map with C++ Pair ON SOLARIS

The below code runs OK in Linux but gives compiler error in Solaris. I am trying to initialize an std pair and then using it to init a C++ Map. It runs perfectly in linux , however Solaris has got an issue with this. Any one has idea what can be done to make it OK in all UNIX variations? #include #...
Parveen
1

votes
0

answer
173

Views

Does a certified (ISO 26262 or similar) C++ standard library exist?

While certified C++ toolchains (compiler etc.) exist I did not find any certified C++ standard library (STL). Does anyone know of someone providing this?
Andreas Pasternak
1

votes
0

answer
94

Views

Reversing a linked list using stl

I am trying to implement reversing of linked list data structure using vectors and standard library.I am getting an error ‘::system’ has not been declared using ::system; #include #include #include using namespace std; int main() { vector v[100]; vector v1; int n,i,k,j,x; cin>>n; for(i=0;i>x...
Ayush Mishra
1

votes
1

answer
53

Views

Custom allocator with a STL vector (within Visual Studio toolchain)

When using a custom allocator with a STL vector (within Visual Studio toolchain) the constructor is called 3 times and the destructor is called 4 times. What am I missing? The following is the code and its output: #include #include #include #include #include using namespace std; template stru...
luc

View additional questions