FAQ Database Discussion Community

## Vectorize thinking

r,vector,vectorization
I'm having a vectorization problem. Say I'm having a vector x <- c(0,0,1,0,1,1,0) , what I want is to get the vector (1,0,1,1), or to remove all the 0s from the first spot to the first non-zero spot and all the 0s from last non-zero spot to the last spot....

## a vector to an upper Triangle matrix by row in R

r,matrix,vector
I have a vector say a = c(1,2,3,4,5,6) I would like to organize them into the elements into an upper triangle matrix (without considering diagonal elements, they are all zero) by row. My goal is to get the following matrix: [,1] [,2] [,3] [,4] [1,] 0 1 2 3 [2,]...

## C++ std::vector of independent std::threads

I´m building a real time software where I have a main infinite loops on main() and threads used to read and process data. One of the issues is keeping a std::vector of running threads to send signals to them and to monitor execution. So I put together this code: #include...

## Is it possible to find an element in a Vec and remove it?

vector,rust
In Rust, is there an in built function for finding and removing elements of a vector, both simultaneously and as separate actions? For example: for f in factors { if f in list { list.remove(f); } } Currently, the rust documentation is still a tad confusing, so while my search...

## Why are non-const vector elements const?

c++,vector,boolean,const,extraction-operator
When I iterate over a vector<bool>, I find that the elements, dereferenced through the iterator, are recognized as if they were const. Why is that? Change either the container or the element type, such as list<bool> or vector<short>, and the elements are non-const. This code shows what I'm talking about:...

## R split vector with jumps

r,vector,split
I have vector created with the following structure: full_seq <- runif(10^8) I want to generate a new vector, extracting samples of the same size. This works fine for me: full_splited <- split(full_seq, ceiling(seq_along(full_seq)/10^3)) Now, I need to jump from one to another chunk by a fixed size. Lets take a...

## Object's container field is empty after move and erase

c++,vector,move-semantics,erase
I have two vectors and I want to move an object from one to the other, before I move it I make a pointer to the object. But when I erase the index in first vector then the container within the object is empty if I access it through the...

## How to simple assign vectors of different structs?

c++,vector,struct
So I have two different structs (a & b) with same variables and an overloaded = operator in struct b to convert a to b. I want to be able to simple assign a vector of a to a vector b, but compiler gives me an error: main.cpp|61|error C2679: binary...

## beginner :While loop not working as it should

c++,loops,vector,while-loop
I am still a beginner and I am learning from a book. There was a drill that asked me filter input based on a vector of filtered words and if it was one of them it outputs "bad word" Here is the drill exactly as in the book. Try This...

## Who should clear a vector retrieved by reference?

c++,vector,pass-by-reference
Let's say I have this very simple code: std::vector<int> getVector( int size ) { std::vector<int> res; for ( size_t i = 0; i != size; ++i ) res.push_back( i* 23 ); return res; } int main () { std::vector<int> v; v = getVector(10); std::cout << "Size1 is " << v.size()...

## vector::push_back ( A * ) creating leaks?

c++,vector,push-back
I'm trying to create a really simple virtual filesystem (represented as a tree)(for my FTP server) mapped to several places on my real one. Nodes are represented by a Node object which holds pointers to its contents in a vector. I know that for every new there is a delete...

## Why do creating pointer to instances beyond certain number(30) of a 'Structure' with 'stxxl:Vector' as one of its DataType fails?

c++,pointers,vector,stxxl
I am using STXXL Library's stxxl::vector in my code as : struct B { typedef stxxl::VECTOR_GENERATOR<float>::result vector; vector content; }; And then creating many instances of the above declared Structure in a loop using the following code snippet : for(i=0;i<50;i++) { B* newVect= new B(); // Passing the above '*newVect'...

## Pass vector of char vectors to char**

c++,vector,stl,char
Is it possible to pass a std::vector<std::vector<char>> to a function void doSomething(char** arr) e.g. to store a bunch of paths similar as with std::vector<char> vec to void func(char *str) vec.assign(64, ' '); Function call: func(vec.data());...

## OpenLayers 3: simple LineString example

javascript,vector,openlayers,openlayers-3
i'm new to OpenLayers and i am looking for some help drawing lines on a map, i've been trying various things from various different posts about drawing LineStrings but i can't get it to work! I just need to figure out how to draw a line between to coordinates. heres...

## How can i copy one vector to another through different classes

c++,vector
i'm trying to make a program in which i want to copy one already defined vector to another, but in different, inherited class. It's something like this: //map.cpp void Map::setQuantity() { std::cout << "set quantity: "; std::cin >> quantity; } void Map::setArray(){ for(int i=0;i<quantity;++i) { cityMap.push_back(City()); } } void Map::showMap(){...

## C language, vector of struct, miss something?

c,vector,struct
This is a part of my program that I want to create a vector of struct typedef struct { char nome; int qtd; int linha; int coluna; } tPeca; tPeca* criarPecas(FILE *pFile, int tam) { int i; tPeca *pecaJogo = (tPeca*)malloc(tam*sizeof(tPeca)); if (pecaJogo == NULL) return NULL; for (i =...

## Using .size() vs const variable for loops

c++,vector,coding-style,const
I have a vector: vector<Body*> Bodies; And it contains pointers to Body objects that I have defined. I also have a unsigned int const that contains the number of bodyobjects I wish to have in bodies. unsigned int const NumParticles = 1000; I have populated Bodieswith NumParticles amount of Body...

## Converting vector to indexed map in Clojure?

dictionary,vector,clojure
Let's say I have the following vector of maps: [{:name "Jack" :age 5} {:name "Joe" :age 15} {:name "Mare" :age 34} {:name "William" :age 64} {:name "Adolf" :age 34}] I want to convert this to an indexed map, like: {1 {:name "Jack" :age 5} 2 {:name "Joe" :age 15} 3...

## converting string to vector in Unity

vector,unity3d,unityscript
I am trying to convert an array of strings in unityscript with values holding values like: "Vector3(5, 3, 8)" into an array of vectors, but Unity will not take these strings as is. Anyone have any ideas?...

## Erasing from vector

c++,vector
I'm tried to erase all elements from a vector. In fact, I wrote that: #include<iostream> #include<vector> std::vector<int> foo(std::vector<int> v) { std::vector<int> result; std::cout << "Initial size = " << v.size() << std::endl; for(int i = 0; i < v.size(); i++) { std::cout << "Size = " << v.size() << std::endl;...

## Does Deleting a Dynamically Allocated Vector Clear It's Contents

c++,vector,destructor,clear,dynamic-allocation
Say I have: vector<string>* foo = new vector<string>(); I add a ton of stuff to it, use it, and then I just call: delete foo; Did I need to call foo.clear(); first? Or will the delete call the destructor. Please no comments regarding the folly of this, I know that...

## std::vector content change when read inside the main()

c++,string,winapi,vector
I was writing this function to search a file inside the computer but i encountered a problem: When I read the files that have been found during the search(using the for cycle inside the main() ) the directory are broken. With some debugging I saw that when pushed inside the...

## STL Push_back string in vector

c++,vector,stl
I am trying to push a string in a string vector, like below void Node::set_val(string &val) { this->val.push_back(val); } But when I try to call it as below Obj.set_val("10h;"); I get the below error, error: no matching function for call to 'Node::set_val(const char )' I assumed that the string in...

## C++ accessing vector of vector got segmentation fault

c++,vector,segmentation-fault
I created a vector of vector (10*10000) and try to access this vector through member function. but I got a segmentation fault. I don't know what's wrong here... Here is Simple.h class Simple { private: std::vector<double> data_row; std::vector<std::vector<double> > data; public: Simple():data_row(10000), data(10, data_row){}; /*initialize data vector*/ int getSampleCounts(std::istream &File);...

## Defining a “vector_cast” template function that works with a variable amount of nested vectors

c++,vector,casting,nested
I want to be able to do something like this for example. std::vector<std::vector<int>> e = {{ 1 },{ 2 }}; std::vector<std::vector<double>> q = {{1.5},{2.5}}; q = vector_cast<double>(e); But also have vector_cast be able to handle any number of nested vectors. Here is my attempt at this. The code works if...

## How to store slider values in a vector

arrays,matlab,vector,slider,value
I'm using Matlab to create a GUI. Herefore I'm using the guide function of matlab. I want to store the slider values in a vector. I am doing this in the callback function: for i = 1:10 X(i) = get(handles.slider1,'Value'); end But this results in a vector that stores the...

## How to have multiple variable function work with vectors

function,vector,scilab
I'm having trouble dealing with scilab functions ; I have an output in the form of a 1x6 vector, and I'd like to have a simple way to make it work with a 6 variable function. v = [1,2,3,4,5,6] ; function z=f(a,b,c,d,e,f) ... endfunction f(v) //returns error Thank you ...

## R vector looping confusion [closed]

r,for-loop,vector
I'm learning R and I have tracked down a problem in my code to an expectation of what looping over a vector would do. Here's what I'm confused by--say I've got a numeric vector with two nonconsecutive elements in it. x <- c(1, 3) If I loop through the vector...

## c++ container very efficient at adding elements to the end

c++,vector,containers
I have been running a c++ program for scientific purpose and I am now looking at optimizing it. The bottleneck seems to be a function where I need to stack pairs of integers. Their number is impossible to know from the start, and I have been using a std::vector of...

## Add same value multiple times to std::vector (repeat)

c++,vector,std
I want to add a value multiple times to an std::vector. E.g. add the interger value 1 five times to the vector: std::vector<int> vec; vec.add(1, 5); vec should be of the form {1,1,1,1,1} afterwards. Is there a clean c++ way to do so?...

## Spacing errors while printing vector to JTextArea

java,database,swing,vector,stringbuffer
So I'm working on making a database system built on top of a Java Swing GUI... I have one button that works to add a person/thing to a vector (in this case the database): // Database Vector<String> db = new Vector<String>(); Here is the button's actionlistener to add: new ActionListener()...

## Is it bad (or even dangerous) to random_shuffle vector of shared_ptrs?

c++,vector,shared-ptr,smart-pointers,shuffle
using namespace std; vector< shared_ptr<MyObject> > objects; // objects gets filled in by something random_shuffle(objects.begin(), objects.end()); Is this bad or inefficient for any reason? Is there a better way of doing it? (I want my array of smart pointers sorted randomly) EDIT: I'm asking because there are going to be...

## libc++ difference between vector::insert overloads

c++,c++11,vector,libc++
The std::vector implementation of libc++ has the following overloads of insert: template <class _Tp, class _Allocator> typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) { pointer __p = this->__begin_ + (__position - begin()); if (this->__end_ < this->__end_cap()) { __RAII_IncreaseAnnotator __annotator(*this); if (__p == this->__end_) { __alloc_traits::construct(this->__alloc(), _VSTD::__to_raw_pointer(this->__end_), __x);...

## Convert MATLAB type: from complex double to double

arrays,matlab,vector,double,complex-numbers
I got a vector of type double let's say vec. When I perform for instance test=vec.^ 1.4623; I end up with test as complex double type, and I am wondering if there is a way to convert test to double since I'd like to get decimal values. ps: It's worth...

## R: recursive function to give groups of consecutive numbers

r,if-statement,recursion,vector,integer
Given a sorted vector x: x <- c(1,2,4,6,7,10,11,12,15) I am trying to write a small function that will yield a similar sized vector y giving the last consecutive integer in order to group consecutive numbers. In my case it is (defining groups 2, 4, 7, 12 and 15): > y...

## C++ vector error C2036: 'int (*)[]' : unknown size

c++,templates,c++11,vector
I am getting 5 compile errors C2036: 'int (*)[]' : unknown size all from various places in the vector class. #include <gl\glew.h> #include "Vector2.h" #include "Vector3.h" #include "WFObjModel.h" #include <vector> #include <memory> using namespace math; using std::vector; using std::string; using io::WFObjModel; using std::unique_ptr; class Mesh { private: GLuint textureID; unique_ptr<vector<Vector3<float>>>...

## Turn std::string into array of char* const*'s

c++,string,shell,vector,posix
I am writing a command shell in C++ using the POSIX api, and have hit a snag. I am executing via execvp(3), so I somehow need to turn the std::string that contains the command into a suitable array of char* consts*'s that can be passed to: int execvp(const char *file,...

## Have an if statement look ONLY at the first word in a string [duplicate]

c++,string,if-statement,vector
This question already has an answer here: how to check string start in C++ 9 answers I have a vector composed of strings, some strings have single words, some have multiple words, some have numbers, etc. I have a code that deletes elements of the vector IF the entire...

## how to sort this vector including pairs

c++,vector
I want to sort in ascending order according to the first element of the inner pair, i.e. a in this case. But its not at all sorting. I am not sure if my function func logic is correct. #include<iostream> #include<algorithm> #include<vector> using namespace std; bool func(const pair<int,pair<int,int> >&i , const...

## RowAction in a Vector source APYDataGridBundle Symfony 2

symfony2,vector,datagrid,doctrine2
Im stuck with this issue for a few days, i currently have grid filled with results from a Stored Procedure, i run a nativequery with the SP, get the results in an Array and use the Vector class from ApyDataGrid to display the results. All of the above is working...

## Sorting vector of Pointers of Custom Class

c++,sorting,c++11,vector
I have vector<FPGA*> current_generation_, which I'd like to sort by FPGA member fitness_ using the sort_members function. Applicable code follows: bool sort_members (FPGA* fpga_first, FPGA* fpga_second) { return (fpga_first->fitness() < fpga_second->fitness()); }; fpga.hpp #include <vector> class FPGA { public: explicit FPGA(int input_gates, int output_gates, int normal_gates); const int fitness(); protected:...

## How to find the set of indices where two vectors have equal elements in Python

python,numpy,vector
I have two vectors in Python: Predictions and Labels. What I would like to do is to find out the set of indices where these two vectors have equal elements. For example, lets say the vectors are: Predictions = [4, 2, 5, 8, 3, 4, 2, 2] Labels = [4,...

## r search along a vector and calculate the mean

r,vector,mean
I have data that looks like: require(data.table) DT <- data.table(x=c(19,19,19,21,21,19,19,22,22,22), y=c(53,54,55,32,44,45,49,56,57,58)) I would like to search along x, and calculate the means for y. However, when using. DT[, .(my=mean(y)), by=.(x)] I get the overall means for the coinciding values of x. I would like to search along x, and each...

## What is the easiest way to initialize a 2d array from a vector of strings?

c++,c++11,vector,multidimensional-array
I have: vector<string> myVector = {0}; myVector.push_back("first"); myVector.push_back("second"); char *list[] = ???? I want it to be initialized like if I was doing this char *list[] = { "first", "second", NULL }; I know I can start allocating memory based on the size and of the vector and the size...

## Reordering vector of vectors based on input vector

c++,c++11,vector,stl,idioms
In a small application, I've been using a std::vector of std::vector<std::string> to temporarily store some data (pulled from a non-SQL database) before processing it and uploading it to a SQL database. Unfortunately, the API from which I am extracting the data does not necessarily return fields in the order specified...

## Segfault while creating a vector of avx vectors

c++,vector,segmentation-fault,intrinsics,avx
for my current project I need to create a vector of 256bit AVX vectors. I used myVector = vector<__m256d>(nrVars(), _mm256_set1_pd(1.0)); which worked fine once but after executing the line twice it gives me a segmentation fault. I was able to come up with the following piece of code vector<__m256d> temp;...

## TypeError: zip argument #1 must support iteration (Vector sum for Ipython)

python,vector,ipython,linear-algebra,ipython-notebook
Hi I'm following "Data Science from Scratch" and I got an error when I was making vector sum function. Could someone help? The code: a = [1,2,3] b = [2,3,4] def vector_add(v, w): """adds two vectors componentwise""" return [v_i + w_i for v_i, w_i in zip(v,w)] vector_add(a,b) #prints [3, 5,...

## C++: Which Data Type in STXXL is suitable to create External Memory Binary Search Tree?

c++,pointers,vector,binary-search-tree,stxxl
I want to create an External Memory Binary Search Tree Data Structure whose data sits in the external memory using stxxl as a library. For this purpose, which Data Type in STXXL is suitable to use as nodes in the Tree. If we use stxxl:Vector as the Nodes of the...

## How to calculate a random point inside a cube

math,vector,3d,cube
I'm trying to figure out the math to find a random point inside a cube. I have something small but it can't take into account the rotation of the cube. Here are some images of my results. Here you can see the cube is rotated to some degree but when...

## Replace the contents of a vector with the values of a matrix

r,matrix,vector,replace
Well, I hope I explain it simple: I have a matrix: matrix(c("a","b","c",1,2,3), nrow=3, ncol=2) with output: [,1] [,2] [1,] "a" "1" [2,] "b" "2" [3,] "c" "3" I have a vector, for example: vector1 <- c("b", "a", "b", "c") I want that another vector to pick the values associated of...

## why vector is always slower than C array, at least in this case?

c++,arrays,vector
I am trying to find all the primes not greater than n using the Eratosthenes'Sieve algorithm, and I have the following codes, with the sieve implemented in vector and C array, I have found that almost during all the time, C array is always faster. Using vector: int countPrimes_vector(int n)...

## Vector of objects from different classes

c++,class,object,inheritance,vector
I'm trying to create a vector containing objects from different classes, derived from a base class. Following answers to this question I've the following code which tries four different ways (commented out below); none of which will compile: class observable { public: virtual void observe(alglib::complex_1d_array)=0; observable() { } }; class...

## Finding a vector that is approximately equally distant from all vectors in a set

python,vector,linear-algebra,mathematical-optimization,approximate
I have a set of 3 million vectors (300 dimensions each), and I'm looking for a new point in this 300 dim space that is approximately equally distant from all the other points(vectors) What I could do is initialize a random vector v, and run an optimization over v with...

## two dimensional vector vs two dimensional array

c++,arrays,vector
I am working on an interview question on leetcode. Longest Palindromic Substring In this question, it reaches memory limit when I use two dimensional vector. But it pass the test when i change it to two dimensional array. It seems like 2-d vector takes more memory than 2-d array does....

## Convert a column of strings in data frame into numeric in R (not the usual kind)

r,string,vector,data.frame,numeric
So in R I have a column consisting of strings that look like something similar to this: "Peter","Paul","John","Melissa","Paul","Peter" ... And I want to convert these names to a numerical ID format, like this: 1,2,3,4,2,1 In other words - I want to create a numerical ID for the names where same...

## reinterpret_cast vector of derived class to vector of base class

c++,vector,c++03
I have a 3rd-party class, say, class A, and a function accepting vector of class A from the same 3rd-party, say f3() (See simplified program below). For easier use of A, I created a derived class B. Many part of my program used class B. The question is, how can...

## sorting vector of pointers by two parameters

c++,sorting,vector
I am trying to sort a vector of pointers to a class A using std::sort, but am having some difficulties. Imagine class A beings just a point, containing x and y coordinates. I want to sort the vector by y coordinates from biggest to lowest using some fixed offset value....

## create vector of objects on the stack ? (c++)

c++,vector,heap-memory
I am creating a temporary vector of pointers to myObject objects. But I am wondering about what happens to the objects I created... { std::vector<myObject *> myVector; myVector.reserve(5); for (int i = 0 ; i < 5 ; ++i){ myVector[i] = new myObject(); } } I assume that at the...

## STXXL: How to sort Vector of pairs on second element?

c++,sorting,vector,stxxl
Similar Question is available here: How do I sort a vector of pairs based on the second element of the pair? but I am interested in External Memory Sorting. I have tried using the analogies from Internal Memory Sorting but the error occurs in sorter_stream.h file of STXXL as: My...

## [ performance]— string::operator+= vs. vector push_back

c++,string,gcc,vector,char
I was testing the performance between these two operations, and on G++ 4.7.3, the string::operator+= version is about 2 times faster. My simple test: What can be the cause of such a big difference? g++ -O2 --std=c++11 #include <iostream> #include <ctime> #include <string> #include <vector> using namespace std; class Timer...

## Create a Triangular Matrix from a Vector performing sequential operations

r,for-loop,matrix,vector,conditional
I have been trying to solve the following problem. Suppose I have the following vector: aux1<-c(0,0,0,4,5,0,7,0,0,10,11,12) where the numbers represent the number of the row. I want to calculate the distance between the differents elements of this vector fixing the first component, then the second and so on. If the...

## How can I generate all the possible combinations of a vector

r,vector
I have a vector, say A,B,C,D,E and I am interested in generating all the possible combination of the vector elements. The desired output is given below. B-A,C-A,D-A,E-A,C-B,D-B,E-B,D-C,E-C,E-D...

## convert unsigned short mat to vector in opencv

c++,opencv,vector,mat
I load a depth image in opencv with cv::Mat depth = cv::imread("blabla.png",CV_LOAD_IMAGE_UNCHANGED); then get a subimage of it with cv::Mat sub_image= depth(cv::Rect( roi_x,roi_y,roi_size,roi_size)).clone(); now I want to convert that sub_image into a vector I try with std::vector<uchar> array; array.assign(sub_image.datastart,sub_image.dataend); that found here in StackOverflow in a similar question but it...

## Matrix / vector multiplication order

opengl,math,matrix,vector
I've read a dozen articles online about the correct order of rotation, translation and scale matrix multiplication in OpenGL. However, now that I started implementing it myself, I came to the point where I'm really confused. Let's assume that in my code I'm calculating the transformation matrix, and I'm passing...

## Using generic iterators instead of specific list types

arrays,vector,iterator,rust
I'm very new to Rust, coming from C# / Java / similar. In C# we have IEnumerable<T> that can be used to iterate almost any kind of array or list. C# also has a yield keyword that you can use to return a lazy list. Here's an example... // Lazily...

## AVX - storing __256 vector back to the memory (void**) in C,

c,vector,void-pointers,memory-alignment,avx
I have the following code extract written in C, double* res; posix_memalign((void **)&res, 32, sizeof(double)*4); __m256 ymm0, ymm1, ymm2, ymm3; ymm0 = _mm256_load_pd(vector_a); ymm1 = _mm256_load_pd(vector_b); ymm2 = _mm256_mul_pd(ymm1, ymm2); ymm3 = _mm256_store_pd((double*)res, ymm3); <--- problem line, When I compile, I get the following error message, error: assigning to '__m256'...

## How to find the closest corresponding vectors between two coordinate matrices?

python,numpy,vector,euclidean-distance
I have the following problem in Python I need to solve: Given two coordinate matrices (NumPy ndarrays) A and B, find for all coordinate vectors a in A the corresponding coordinate vectors b in B, such that the Euclidean distance ||a-b|| is minimized. The coordinate matrices A and B can...

## Cannot Properly Print Contents of Vector

c++,arrays,string,vector,segmentation-fault
I have some C++ code where I'm taking input from a user, adding it to a vector splitting the string by delimiter, and for debugging purposes, printing the vector's contents. However, the program only prints the first location of the vector, and then none of the rest. main.cpp #include <cstdlib>...

## Java Vector wrong output

java,vector,output
My problem is, when I add for example 3 inputs in Vector and when I display the result I only found the last output. XMLTable, Table,Column = classes cols : the vector who contain the problem Code : btnSave.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { XMLTable xt= new XMLTable();...

## c++ vector bubble sort

c++,c++11,vector,bubble-sort
I use g++ -std=c++11 Sort.cpp to compile my file. My problem is the bubble sort don't sort. Maybe I'm passing the vector by value but I don't know is closely my firt time trying work with c++ and I chose use vector library. My code is: #include <iostream> #include <vector>...

## Vector of Vector of object

c++,arrays,vector,segmentation-fault
I have a little problem using vector of vector. I have a std::vector<AObject*> _word in my class, I build my word : AObject *object = new Letters(); _word.push_back(object); Later I use : for (size_t i = 0 ; i < _word.size() ; ++i) _word[i]->draw(); ^ THIS WORKS BUT I NEED...

## Add a matrix of 2x2 into a vector in c++

c++,matrix,vector
I am trying to fill a vector with a matrix of values in c++. I'm not very self confident with this procedure (I don't know well about pointers and I don't know if I need it here) however I am trying this int auxMat[gray.rows][gray.cols]; vector<int> collectionSum; collectionSum.push_back(auxMat); When I try...

## R - How to re-order row index number

r,vector,indexing,data.frame,row
Simply put, I have the following data frame: Signal 4 9998 3 549 1 18 5 2.342 2 0.043 and I want to reset the index numbers to be like : Signal 1 9998 2 549 3 18 4 2.342 5 0.043 ...

## C++ delete elements in vector

c++,vector
int main(){ vector<Customer*> newcustomer; newcustomer.push_back(new Customer("III", 123333, 555)); newcustomer.push_back(new Customer("LOL", 122222, 444)); newcustomer.push_back(new Customer("PPL", 121111, 333)); for (int i = 0; i < 3; i++){ cout << newcustomer[i]->getName() << endl; cout << newcustomer[i]->getPhone() << endl; cout << newcustomer[i]->getID() << endl; cout << endl; } system("pause"); return 0; } So I...

## Segmentation fault in list of objects

c++,design-patterns,vector,segmentation-fault,copy-constructor
I didn't thought that this would be so hard, but I have the following program: In a multithreaded environment (using the ACE-Framework and OpenMP) I use the Observer pattern. In the init-routine of the Observer-controller-thread (ActiveObject) I create a vector of ConcreteObservers (for notifying them with their discrete job) like...

## Copy vector into char*

c++,vector,char,c-strings
I'm just studying C and C++ programming. I've searched and can't seem to find an answer that has a decent response. Of course using <string> is much easier but for this task I am REQUIRED to use only clib <string.h> functions; I'm also not allowed to use C++11 functions. I...

## c++ vector erase function not working for specific words?

c++,vector
I am using a very simple function in c++, vector.erase(), here's what I have (I'm trying to erase all instances of these three keywords from a .txt file): First I use it in two separate for loops to erase all instances of <event> and </event>, this works perfectly and outputs...

## Extracting vector graphics (lines and points) with pdfclown

vector,graphics,pdfclown
I want to extract vector graphics (lines and points) out of a pdf with pdfclown. I have tried to wrap my head around the graphics sample but i cannot figure out how the object model works for this. Please can anyone explain the relationships?

## Best way to access vector objects

c++,vector,iterator
If I have a vector, std::vector<int> MyVector; And want to access the n'th element of that vector, I can do so in many different ways: int x = MyVector[n]; or int x = MyVector.at(n); or even using iterators that I am not familiar with. I am sure there are also...

## Debug error: Vector iterator not dereferencable and Vector subscript out of range [closed]

c++,vector,stl,iterator
I am trying to implement Rateless codes, but I have some issues in decoding. In the first implementation I used iterator to loop over a vector of vector and do some operation (like erase()) but I was getting this debug error: Vector iterator not dereferencable. After some googling I found...

## R Program Vector, record Column Percent

r,vector,percentage
This is my vector head(sep) I must find percent of all SEP 11 in each row. For instance, in first row, percent of SEP 11 is 100 * ((63 + 124)/ (63 + 124 + 0 + 0)) And would like this stored in newly created 8th column Thanks dput...

## Address of an instance emplaced to std::vector is invalid

c++11,vector,standards,emplace
I have 2 std::vectors: to first vector, I emplace instance to second vector, I want to store the address of the instance just emplaced But it does not work, i.e., the stored address differs from the emplaced instance's address. If it matters at all, I'm on Linux and using g++...

## How to iterate through a vector of nodes

c++,vector,graph,dijkstra,shortest-path
I am implementing Dijkstra's shortest path algorithm. I have made a node class as follows: node::node(int to,int weight) { this->to = to; this->weight = weight; } I have made a graph class as : class Graph { int V,E; vector<node> *adj; public : Graph(int V,int E); void addEdge(int v,int w,int...

## Sending vector data in the bus

I have a vector data (an array variable for example float32 mydata;). for transmitting a single primitve/basic data in a bus its pretty simple. inside_data=Simulink.BusElement; inside_data.Name='somename'; inside_data.SampleTime = -1; inside_data.datatype='single'; this element can be put inside a using Bus=Simulink.Bus; Bus.Elements=inside_data; But this works when the input is a primitive. But...

## Concatenate numbers in a vector to form one number

c++,vector
I have a function which feeds a vector series of numbers. This series of numbers is to be appended to form a long long number and get stored in another vector. Eg. Vector1= |2|3|4|5|5| vector2= |23455| | A space indicates the end of one number and functions starts to output...

## Convert Vector to String?

java,vector
I have a problem, when I am converting vector to String. Error: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.util.Vector cannot be cast to java.lang.String at Package_Sync.Package_sync.dataToDB(Package_sync.java:98) at Package_Sync.Package_sync.<init>(Package_sync.java:29) at Package_Sync.Package_sync\$3.run(Package_sync.java:319) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756) at...

## cannot convert parameter 1 from 'std::_Vector_iterator<_Myvec>' to 'std::_Vector_iterator<_Myvec>'

c++,vector
I have a question, its a bit hard to discribe it so be easy on me please. I have two classes, A and B, class A have a private member- vector: class A { private: struct complex { int x; vector< int > y; }; vector< complex > m_resultVector; //...

## C++ 2D vector - Convert int to double

c++,vector
What is a good way to convert vector<vector<int>> vint to vector<vector<double>>vdouble? I know from C++ convert vector<int> to vector<double> that this can be done for 1-D but I am not too sure how to do it for 2-d case....

## WorldToScreen function C#

c#,vector
Can anyone please explain the world to screen function (c#) to me? I want to understand what it does, how to use it and what I need to use it. So far I know, that it converts 3d vectors to 2d vectors, that then can be shown on the monitor....

## Getting Values of Specific Elements of a data frame in R

r,vector,data.frame,r-factor
I have a very simple code, I do not understand why not working the way I want. Basically, I have a data frame and want to capture the value of n'th element of a column in the data frame, and store it in a vector. Here is my code: COL1_VALUES...

## Vector : References to generic type Vector should be parameterized

jsp,generics,vector
I have this problem(yellow line) in my jsp file which often caused my eclipse program keep no responding. Although my program can run, but how can i get a rid of this following line of code. Vector vFieldName = (Vector) session.getAttribute("table_vFieldName_"+TABLE_TYPE); Vector vTable = session.getAttribute("table_vTable_"+TABLE_TYPE) == null ? new Vector():...

## Add coefficients of a vector to a matrix

r,matrix,vector
I would like to add each coefficient of a vector to each different column of a matrix. For example, if I have a vector and a matrix: x <- c(1,2,3) M <- matrix(c(5,6,7), nrow = 3, ncol = 3) I would like to in my new matrix M1 1+5 in...

## Is it safe to compare to pointer of std::vector to check equality?

c++,pointers,c++11,vector
at a time, I created a pointer point to a std::vector, then I did some push_back, reserve, resize operation to that vector, after such operations, is it safe to compare the pointer to the address of that vector to check whether the pointer point to that vector, because there might...

## program failed. sharedPtr vector c++

c++,vector
PLEASE, i realy need help.. don't panic from the sharedPtr implementation I'm having a problem with my project in c++. In my project, I'm creating a company which holds all the information about its employees (artist, programmer,manager), projects ,... for holding all the employees I use a vector of SharedPtr(use...

## decltype does not resolve nested vectors. How can I use templates for nested vectors?

c++,templates,vector,nested
I am trying to overload the + operator to deal with nested vectors. I thought the function would call itself until the nested vectors resolve to basic types, but instead I get a huge list of errors when I compile it. My vector operations that I have defined work for...

## Filter operation from vector to vector

c++,vector
I'm trying to implement a filter operation which takes a vector V and creates another vector D with the filtered elements of V. The result can't be a pointer and I'm not allowed to use a regular for loop/while. I was thinking of using: for_each, copy, copy_if but none seem...

## Heap Corruption using cv::FlannBasedMatcher and std::vector

c++,opencv,vector,feature-extraction,heap-corruption
I am developing a breast imaging features for object recognition, using FlannBasedMatcher to compute spatial histograms. Mat ComputeSpatialHistogram(Mat features, Mat vocabulary, int* region_index, int level, Ptr<DescriptorMatcher> flann_matcher) { int vocab_size = vocabulary.rows; Mat descriptor = Mat::zeros(1, vocab_size*my_pow(4, level), CV_32FC1); if (features.rows > 0) { vector<DMatch> matches; flann_matcher->match(features, matches); int word_idx,...

## What's the fastest way to compare point elements with each other？I have used Nested for loop to do that, but it's very slow

c++,opencv,for-loop,dictionary,vector
I want to find the points which the distant between points less than 3.For example, some points as follow, (220,221)(220,119)(220,220)(20,90)(220,222). I use (220,221) to find points.Then i can get (220,221)(220,119)(220,220)(220,222) I use (220,119) to find points.Then i can get (220,221)(220,119)(220,220) I have used Nested for loop to do that, but...

## Using vector with derived classes

c++,vector
I'm trying to use a vector for derived class Employee but I got en error: class Company : public Employee, public TesterEmployee, public DeveloperEmployee { private: std::vector<Employee*> _table; public: friend std::vector<Employee*>& operator+=(const Employee* emp) { _table.push_back(emp->clone()); return *this; } }; The error is: error: 'std::vector<Employee*>& operator+=(const Employee*)' must have an...

## Compare values of two vectors

r,vector,compare
I have two vectors: a <- c(23,43,54) x <- c(1,543,65,89) I would like to have a vector y of dimension 4 - (dim(x)) which indicates how many values of the vector a are upper than each coefficient of the vector x. Is there a function that does this task?...