Questions tagged [vector]

A vector is a single-dimensional array: it contains components that can be accessed using an integral index. In some languages the size of a vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created. Use 'vector-graphics' for graphic display.

-1
votes
0answers
4 views

How can I store an std::vector of objects as a nlohmann::json ? And backwards? [duplicate]

I try to store a vector of "Person" objects as a nlohmann::JSON object. How can I do it? this is the Person struct: struct RoomData { unsigned int id; std::string name; ...
-1
votes
2answers
28 views

How to sort a class member vector?

I'm working in a code that sorts a list with a key for each element, and I'm using the STL function sort. However the key function that I need must be a non-static function of a class, and the ...
1
vote
3answers
45 views

Reversing an array (vector) using reverse_iterator

I'm trying to improve my c++ knowledge using Edabit challenges and testing out 'new' functions. Current challenge wants us to write a function to reverse an array. examples: reverse([1, 2, 3, 4]) ➞ [...
0
votes
1answer
54 views

Can't seem to push_back abstract objects into vector?

I am trying to create one vector for two types of users. Admin and Customer who are both derived from an abstract class, BaseUser. However I tried some of the answers provided online but I can't seem ...
-1
votes
1answer
71 views

How can I fix this error: Invalid operands to binary expression ('std::vector<double>' and 'double')?

I want to obtain the average of some gyro readings and it involves dividing an std::vector<double> type with a double type, but I get the following error that reports Invalid operands to ...
0
votes
0answers
7 views

Getting the location of a bone matrix to render separate meshes to this location?

I have an skeleton animation system that I piece together using multiple sources. What I am wondering is how I can get the bone location and render a separate mesh/Item to that bone location e.g. ...
2
votes
1answer
43 views

Numpy: Fastest way to compute angle between 2D vectors

I'm looking for efficient alternate ways to compute cosine angle between 2D vectors. Your insights on this problem will be of much help. Problem Statement: vectors is a 2D array where vectors are ...
3
votes
2answers
59 views

Vector insert within the same object

I was trying to insert few values from a vector to that same vector object but it seems to have erred: #include <iostream> #include <vector> int main() { std::vector<int> vec = ...
-9
votes
1answer
60 views

vector<vector<int>> seq(n); What does this statement mean? [on hold]

Here seq is the name of a vector and 'n' is an integer value. I am solving a problem based on dynamic arrays.
1
vote
2answers
36 views

Vector error,a very confusing segmentation error?

So basically,I am doing a code which searches for an element of a vector inside a vector.While I thought of the approach , implementing it got me a segmentation error. I narrowed down the problem ...
0
votes
1answer
16 views

Why I am getting segmentation error in this code?

Input Format : Line 1: An Integer N, denoting the number of binary strings. Next N lines: strings of equal length Output Format : Return the minimum number of touches. (Integer) Sample Input : 2 ...
-1
votes
0answers
23 views

How do i make the minecraft player look at a block

Currently im coding a mod for minecraft. I wanna be able to make the player look at x, y, z coordinates. I also want to be able click at that block at those x, y, z coordinates(and therefore breaking ...
-3
votes
2answers
64 views

Why is vector of unique_ptr the prefered way to store pointers?

What I have readen say that a common approach to make a vector of pointer that own the pointers, of MyObject for example for simples uses, is vector<unique_pointer<MyObject>>. But each ...
2
votes
1answer
68 views

Why does R strip names of vector extracted from a one-column matrix with named rows?

I want to take one row of matrix M and treat the row as a named vector, with the column names of the original matrix as the names of the vector. Usually M[x, ] does what I want but this fails if: (a) ...
1
vote
1answer
60 views

In Rust, is there a way to perform a retain() on only part of a container?

I'm learning Rust for fun, and when writing a function to return the nth prime, I realized my solution felt inelegant and wasteful. I iterate through my entire list of possible primes, when I only ...
-1
votes
0answers
17 views

How to define wstring ToString<vector<unsigned char, allocator<unsigned char> > >(const vector<unsigned char, allocator<unsigned char> >& uc)

For some reason the C++ compiler throws an error in this line Assert::AreEqual(vector(), vector()); I have tried implementing these two functions without success. template<> template<...
-1
votes
1answer
47 views

How to fix: for loops not reading for a vector

School assignment for coding a cows and bulls game. Final scoring loops not working and I am not sure what the reason is. I have tried renaming the vectors, changing iterators, changing where in the ...
0
votes
0answers
29 views

HackerEarth Queue Data Structure

There is a queue of N spiders of which only X spiders are to be selected. Each spider has some power associated with it. There are X iterations on the queue. In each iteration, X spiders are dequeued (...
0
votes
4answers
88 views

What is the difference between begin () and rend ()?

I'm learning to 'iterator' and I have a question about the difference between begin() and rend(). #include <iostream> #include <array> #include <vector> #include <algorithm> ...
0
votes
1answer
34 views

Deallocating the Vector memory after using it once?

I am looping n number of times and in each loop I want to allocate the memory to a new vector and after computing I want to deallocate the memory and again want to allocate new in the next loop. C++ ...
0
votes
0answers
6 views

What's the difference between Regular array and Big array in dolphindb?

In the manual of dolphindb, the functions to build them looks familiar: x = bigarray(int,10,10000000,1); x = array(int,10,10000000,1); I could also build a same length array.... But I'm intrest in ...
0
votes
0answers
28 views

Error when using the template class copy constructor

I can not write copy constructor. How to fix the error? Tried to fix it like that: template<typename T, typename A> vector<T, A>::vector(const vector<T, A> &other) { this-&...
1
vote
0answers
51 views

std::vector<Eigen::Matrix4f> allocated memory but fails to access its elements

I created a vector which contains 100 Eigen::Matrix4f. But when I use transforms[i] to access its elements, the programme shows "core dumped: segmentation fault". When I use push_back() function to ...
-1
votes
0answers
27 views

vector of void* elements create and delete [duplicate]

I want to create a vector that can store int and double values at the same time. Just for learning, I know I could use boost::hold_any or struct {int a, double b}. My problem is that right after an ...
0
votes
0answers
20 views

Error in model$x %*% t(model$rotation):requires numeric/complex matrix/vector arguments

I am trying to plot a pca graph with one hot encoding of DNA data. the data was stored in a dataframe(all_coded) as +----------------------------------------------------------------------------------...
0
votes
1answer
38 views

How does ARM find my relocated vector table?

I'm using an NXP Kinetis K64 ARM Cortex M4 MCU. I successfully altered the linker configuration file to move my vector table to address 0x8000 (instead of the 0x0000 default). When I tell the ...
0
votes
2answers
58 views

Looping over vectors (NOT looping over elements in a vector)

fellow stackers I currently have, say, 2 vectors x <- 1:2 y <- 3:4 I am looking to do something like for (i in c("x","y")) { i <- data.frame(i) i$flag <- ifelse(i == "x", 1, 0) # ...
0
votes
1answer
28 views

Using each element of a vector in a series of calculations

I am trying to write MATLAB code that uses a set of variables in a vector in a calculation. I am trying to run the same formula with each value in the vector and then store each result in a new ...
0
votes
3answers
74 views

Why does this happen in with vectors

I have been writing code to add books to a library.When I add the books to the library and try to display it stores(displays) nothing in the library Here I set the maximum number of books the ...
0
votes
1answer
40 views

Does there exist a data structure in cpp that easily provides a way to build a new one, based on an instance that already exists?

The type of operation I'm looking for would go as follows, but of course this code doesn't work. int a[3] = {0,1,2}; int b[3] = (a[2] = 0); This way the array b has elements {0,1,0} and a has {0,1,2}...
1
vote
1answer
32 views

How to import data from ascii file into a vector in R?

I don't know how to import data from ASCII file into a vector. Here is my data look like: 42019*1 3738.937 21*1 3413.974 20*1 3439.52 3287.071 20*1 3078.413 3144.528 20*1 2695.402 2817.517 20*1 2360....
1
vote
0answers
86 views

Why std::vector<bool> does not specialize the lexicographically compare function?

I know that std::vector<bool> is a space-efficient specialization of std::vector for the type bool. I look up the clang and gcc's implementation and find that they use the underlying storage ...
2
votes
2answers
64 views

Sorting multiple data members [duplicate]

What should be the best approach to make multiple sortings in vector of pointers (std::vector<SomeObject*)? Should I make one sorting function for multiple data members and what would be the best ...
0
votes
1answer
15 views

Is it wise to use Glide to load XML vectors

Does Glide know to differentiate between images and vectors? Is there any advantage for loading an XML vector using Glide in terms of memory usage and cache management? GlideApp.with(imageView) ...
0
votes
1answer
23 views

Appending vector values to sublists

Let's assume we have a list with three sublists: list1 <- [[1,2],[4,5],[7,8]] and a vector: vector1 <- c(3,6,9) Is there a way in R, without using loops, to append vector's values to the list, ...
3
votes
2answers
50 views

std::vector<std::vector<int>>: Debug assertion failed. C++ vector subscript out of range reserving memory [duplicate]

What's wrong here? std::vector<std::vector<int>> mSectionsSubsets; int count = (int)powf(2, NUM_SECTIONS); mSectionsSubsets.reserve(count); for (int i = 0; i < count; i++) { ...
0
votes
0answers
6 views

Is there any way to convert a vector to euler angle?

I have 2 vectors in 3D space, for example: If I know these 4 points, is there any method to find out the euler angles of them? I am trying to move these two vectors to the origin, then assuming ...
0
votes
0answers
16 views

std::vector< int64_t> trduced from c++ to java returns SWIGTYPE_p_in64_t which is unusable

I am trying to use swig (v3) to transform a function which have a std::vector as entry to a java code. but when compiling with swig, I got a file with a class StdVector_int64 with a method get(int i) ...
0
votes
1answer
61 views

How to convert an Vector of strings to an Vector of uint8_t

Short Version: I have a String: 0x4D;0x90;0x69 I want an array static const uint8_t array[] = { 0x4D, 0x90, 0x69 } How to do? ​ Longer Version: I have an String (buffer) with like this: ...
0
votes
0answers
12 views

Generate vector field pointing to minimum intensity (black)

I have a black and white image and want to plot a vector field that points to the highest and nearest minimum intensity value (something like the arrows shown in the image). Similar to Gradient filter ...
0
votes
2answers
78 views

How to copy one object from a vector to another vector in C++?

I have a Product class which represents a single product object, each new Product object is stored inside a vector that is part of the Catalog class. I want the user to be able to add products that ...
-1
votes
2answers
79 views

what's wrong with this function? it shows no error but keeps giving output as 0

A string is said to be a child of a another string if it can be formed by deleting 0 or more characters from the other string. Given two strings of equal length, what's the longest string that can be ...
0
votes
2answers
43 views

How do I read a text file into a 2D vector?

Your help will be appreicated in this matter. i have to read a text file which has rows and columns into a vector. The text file could be of any size. One example of text file: T,T,T,F,T T,T,T,T,T T,...
-1
votes
1answer
43 views

How to push_back an object in a vector inside a struct [closed]

I'm coding a program using binary tree, I need to add a node as a son, so I used a struct. So I'm trying to add the child by looking for the adresse of his father, I keep getting an error that there ...
2
votes
2answers
74 views

How to use the map function on a vector of maps in clojure

how are you all? I'm quite new to Clojure and I'm facing a problem I guessed would be easy to solve but I can't seem to get a grasp on. I have a method which generates a vector of coordinates in a ...
0
votes
0answers
10 views

converting diagonal matrix into column vector in R

I want to convert a diagonal matrix into a column vector in R Here is an example diagonal matrix PC1 PC2 PC3 PC4 PC1 0.002588556 0.000000000 0.000000000 0....
2
votes
3answers
55 views

Initialize a 2D vector inside constructor of class

I want to initialize a 2D array in the constructor of a class but the compiler gives me this error "call of an object of a class type without appropriate operator() or conversion functions to pointer-...
1
vote
1answer
27 views

C++ Table of Vectors of Different Types

I have a collection of vectors of different types like this: std::vector<int> a_values; std::vector<float> b_values; std::vector<std::string> c_values; Everytime i get a new value ...
0
votes
2answers
67 views

problem using erase function for a vector in c++ “No Matching Function”

The code is about finding the sum of first x prime numbers and I am using Sieve of Eratosthenes algorithm. I haven't seen any tutorial for code, I just studied the concept and trying to implement on ...
-4
votes
5answers
85 views

Problem with code. Using vector delete same numbers except the last entrance of it

The program dosen`t work but there are no errors. I need to delete numbers exept the last entry. We have 1 2 3 4 1 2 5 7 8 0 0 we need to get 3 4 1 2 5 8 8 0. Included libraries: vector,iostream. ` ...