Skip to main content
Advice
1 vote
5 replies
162 views

Why can't you just do this? int index = 0; std::string example; std::cin >> example; std::vector<std::string> list; list.push_back(example[index]); I'm a complete beginner in c++ and I ...
Filipos's user avatar
Advice
1 vote
13 replies
92 views

I do things with maps (could be std::map or another map from the standard library, a boost map, a custom map from another library, etc): template<class T> void do_map_stuff(T const& t) { ...
jaymmer - Reinstate Monica's user avatar
Best practices
0 votes
12 replies
6k views

I have the following problem. There is a class A and B where B derives from A. There is a third class C which needs to hold a std::vector<A> or std::vector<B> I want the data to be as a ...
goaran's user avatar
  • 515
0 votes
0 answers
181 views

it -> a random valid vector iterator const int kLookAheadIndex -> a random number auto it_ahead = std::max(it - kLookAheadIndex, path.cbegin()); // get a look-ahead point to look at I know ...
Bill Kotsias's user avatar
  • 3,420
0 votes
1 answer
105 views

I am trying to populate a std::vector container using another std::vector and tbb::parallel_for method as shown in the following code snippet: #include <tbb/parallel_for.h> #include <eigen3/...
abhi.goudar's user avatar
2 votes
2 answers
212 views

Im wondering if there is a better, more typesafe, way to return "a selection" than I do at the moment. If we only ever have one selected element at a time, we can just return a reference, ...
darune's user avatar
  • 11.5k
3 votes
1 answer
257 views

System is: Ubuntu Linux 20.04.6 LTS g++ version 9.4.0 IDE QTCreator I have two vectors (set and subset), subset needs to be transferred into set, at location (0,0), such that, the rows are padded ...
Mike's user avatar
  • 691
4 votes
2 answers
207 views

I have the below code. The first push_back fails, the second, with a constant string, works. #include <vector> #define MAX_LENGTH 10 struct bar { int barInt; char barChar [...
Peter VARGA's user avatar
  • 5,371
1 vote
0 answers
58 views

What is the category of std::views::transform based on a std::vector? What is the category of the view's iterator in the following code? #include <iterator> #include <memory> #include <...
Krzysiek Karbowiak's user avatar
0 votes
1 answer
203 views

std::map<unsigned long, std::vector<Foo*> > fKeys = myObject->GetFoo(); for (auto it = fKeys.begin(); it != fKeys.end() && !found; ++it) for (auto it1 = 0; it1 < (*it)....
Igor's user avatar
  • 6,550
-2 votes
2 answers
268 views

I have a simple C++ program that manages as a todo list. The Todo, class contains a vector of Item to track each todo action and their id. The key constraint is that the ids must be kept strictly ...
0ro2's user avatar
  • 1,036
4 votes
2 answers
228 views

My problem is the following : std::vector<struct pollfd> vec = { ... }; // Actually a member variable on a Server object for (auto iter = vec.begin(); iter != vec.end(); ) { if (...
Azyrod's user avatar
  • 150
-3 votes
1 answer
249 views

I want to use auto more in my code and came up with the following example: #include <vector> int main() { auto v{std::vector{}}; for (auto i{0}; i < 10; i++) { v.push_back(i)...
Panic's user avatar
  • 93
3 votes
2 answers
125 views

This is my test code: #include<vector> #include<iostream> #include<type_traits> using std::vector; using std::is_same_v; using std::cout; using std::endl; int func() { struct ...
Vinod's user avatar
  • 1,259
7 votes
1 answer
255 views

The elements in the array are not default constructible therefore we need to initialize the array directly from elements in std::vector. #include <array> #include <vector> class foo { ...
 sentientbottleofwine's user avatar

15 30 50 per page
1
2 3 4 5
206