Click here to Skip to main content
15,887,175 members
Everything / Vector

Vector

vector

Great Reads

by Clayton Rumley
There are those who think I am crazy, and this just might be the proof.
by Sergey Alexandrovich Kryukov
Another variant of the cross-platform replacement for all those office presentation applications in a single file, and now this file is JavaScript
by Arthur V. Ratz
Optimizing the performance of the large-sized matrices QR factorization and eigendecomposition, using Schwarz-Rutishauser algorithm
by Arthur V. Ratz
Compute the Levenshtein distance of literal strings effectively by using the Wagner-Fischer (two matrix rows-based) algorithm.

Latest Articles

by Nicolas DESCARTES
What are vector databases?
by Sergey Alexandrovich Kryukov
Another variant of the cross-platform replacement for all those office presentation applications in a single file, and now this file is JavaScript
by Arthur V. Ratz
Compute the Levenshtein distance of literal strings effectively by using the Wagner-Fischer (two matrix rows-based) algorithm.
by spore123
This is a fast multi-threaded quick-sort based algorithm

All Articles

Sort by Updated

Vector 

19 Feb 2024 by 0x01AA
There is I direct way without first declaring a helper vector: vector > myVector { /* Element 0 */ {1, 2, 3, 4}, /* Element 1 */ {5, 6, 7, 8}, /* Element 2 */ ...
14 Mar 2015 by _Maxxx_
If point(0) is at (x,y)then it forms a triangle with points(x,y) , (x, y+n) , (x + SQRT(n2 - (n/2)2) , y + (n/2))where n is the length of side of the triangle - which is N / 3 where N is the hexagon side length.now you have the coordinates of triangle (0,1,5) every other triangle...
16 Apr 2015 by Amir Hossein Farzaneh
I am initializing a vector in a class using 4 threads by passing arguments to threads: //main.cpp #include "stdafx.h" #include #include #include "class.h" using namespace std; int main() { myCLASS* classObject = new...
18 Oct 2014 by Andreas Gieriet
Try leaving away the address-of operator while instantiating the function and pass the data in the template by reference.CheersAndi
17 Dec 2015 by Andreas Gieriet
See the definition of pop_back().E.g. from http://www.cplusplus.com/reference/vector/vector/pop_back/[^]. It says that pop_back() from an empty collection is undefined behavior, which includes "crashing".[EDIT]Your logic is broken: while(!human.empty() || !zombie.empty()) ... is also...
17 Aug 2016 by Anti-Antidote
OK, so this will take a bit of explaining, but I'm new to C++, so bear with me. What I am trying to accomplish in my program is to have the user add an 'item' with certain attributes (these are my class variables). Every time the user adds another 'item', I want the program to assign another...
10 Sep 2017 by apurv625
I am changing the signature of a function having default argument char* to vector in C++. The role of function with default argument char* is to take out the image name of an image file, then read that image file and send to the server. This function is only capable of sending one image...
12 Dec 2015 by Are Riff
#include #include #include using std::cout;using std::cin;using std::endl;using std::ostream;// Random value generator functiondouble randomize(const double &minVal, const double &maxVal){ std::random_device rd; std::mt19937...
15 Dec 2015 by Are Riff
I am learning about dynamic memory and have a question.Let say I have this class.class Elf {private: double _health = 0;public: Elf(const double &health){_health = health;}};I can create an Elf object using smart pointer like this.unique_ptr vec1 =...
5 Apr 2017 by Are Riff
I am learning about smart pointers.class Elf {private: int _health = 0;public: Elf(const int &health){_health = health;} int getHealth(){return _health}};What is the different between these two?First case:vector> elves;for (auto i = 0; i
17 Dec 2015 by Are Riff
The code is here. It's almost 1000 lines. The first 800 lines are just class and declaration. The problem start at around line 910+.http://cpp.sh/7qrh[^]I have this code here, it compiles ok. But it crashes when executing pop_back() on the vector in line 919.It crashes and show the...
3 Jan 2022 by Arthur V. Ratz
Optimizing the performance of the large-sized matrices QR factorization and eigendecomposition, using Schwarz-Rutishauser algorithm
16 Sep 2022 by Arthur V. Ratz
Compute the Levenshtein distance of literal strings effectively by using the Wagner-Fischer (two matrix rows-based) algorithm.
10 Apr 2021 by Bhavini Amin
I am currently writing a programme to calculate the one day VaR using the historical simulation method. Within the programme I am first calculating the daily returns of the prices which the excel formula is Close_price_today -...
19 Dec 2015 by BladeLogan
Hello there! I've been overlooking some logo's latley & the ones that cought my attention was thesehttp://imgur.com/HrXl9EH[^]What are those type of logo's called? & is it possible to create them in Photoshop?
13 Aug 2023 by Brennon Nevels
My friend and I are building a text-based game. But the problem so far is I cannot figure out how to resolve this problem. The goal was to make two functions. One to print a vector and another to find a specific element within. #include...
12 Sep 2023 by Brennon Nevels
While I'm aware that this is just a simple thing to do, I've tried to make this into a function. While mine kind of works, I'm more interested in how other people would go about it. #include #include #include ...
30 Jul 2014 by chandanadhikari
hi,for simply comparing 2 vectors you can check this out [^]hope it helps !
7 Feb 2014 by charles henington
I'm currently in the process of writing a code snippet that converts a Raster image to a Vector image. It works but the output becomes quite large on larger images, ex. on an 960px * 800px image the output is around 160mb, I've searched relentlessly on google for a solution of creating an array...
24 Jan 2023 by Chillzy
I'm trying to convert C++ code to C and it was all fine until I got to the .push_back() function. After some research, I found out this wasn't a function in C. How do I write a function in C that replicates the uses of the .push_back() function? ...
27 Apr 2016 by Clayton Rumley
There are those who think I am crazy, and this just might be the proof.
8 Jan 2018 by CodeBlooded
So, I what I want is to collect maximum element from each row(in a 2D vector) and push it into a new vector. And if the new vector is sorted I want the sum of all vector elements. I tried it but the code is showing error : "cannot convert 'std::vector to 'int' assignment" also, is my code...
23 Aug 2015 by CPallini
You aren't getting a compilation error, you're actually getting a runtime exception.Looking up the ArrayStoreException in the Java documentation[^] you might find that you are trying to fill an array of doubles with integers (and you cannot do that).
18 Nov 2015 by CPallini
Try:void Agent::delete(int flightNumber){ vector::iterator ptr; for(ptr=flightList.begin();ptr!=flightList.end();ptr++) { if( ptr->FlightNumber == flightNumber) { flightList.erase(ptr); return; } } if ((ptr)...
3 Oct 2016 by CPallini
You may use std::unique after std::sort. See the sample code at std::unique - cppreference.com[^].
30 Nov 2016 by CPallini
As suggested by enhzflep, it is the first parameter that doesn't fit.Try#include #include #include using namespace std;int main(){ vector v; v.push_back("A"); v.push_back("C"); vector::iterator it = v.begin() + 1; ...
31 Jul 2017 by CPallini
Have a look at Serialization[^]. I suggest you to add serialization support to your Medicine class (e.g. load/save methods) and then iterate over the vector items in order to serialize the whole container.
10 Sep 2017 by CPallini
The straightforward way to do that is overloading the old function (and call it): void fileSend(vector fnames) { for (int k = 0; k
19 Sep 2017 by CPallini
You are trying to complicate a simple matter. Try #include #include using namespace std; // Please note: error handling (e.g. a.size()!=b.size()) left as exercise int dot(const vector & a, const vector &b) { int dp = 0; for (size_t n = 0; n
4 Feb 2018 by CPallini
Quote: int *temp; temp = new[]; Let's fix your starting point. The above statemens should be int * temp; temp = new int[col.elno + 1]; Now your temp vector as the right number of items. You have to Copy all the col.elements items into temp. Add element at the end of temp. ...
13 Aug 2019 by CPallini
Quote: def.pop_back(line);//too many arguments in a function call (red line on "line") The correct method is push_back, see vector::push_back[^]. The pop_back method is used for deleting the last element of the vector.
28 Mar 2020 by CPallini
A diagonal starting at (row,0) includes all items (row+k,k) where k=0,1,.., ROWS-row-1. In a similar way, a diagonal starting at (0,col) includes all items (k,col+k) where k=0, 1, .., COLS-col-1. The task is competed if you iterate on rows: row...
3 Nov 2020 by CPallini
You could also overload the insertion operator ...
21 Feb 2022 by CPallini
You need a containers for your subvectors. You might, for instance, use a vector of vectors: #include #include using namespace std; int main() { vector v{2,3}; vector > sv; // the sub-vectors ...
24 Jan 2023 by CPallini
Quote: ll the code is in C++ and not C, which is a problem because I work in C, due to it being better than C++ (rather structs and unions than classes and templates and whatever bs C++ has to offer). Use C++ if you can. C++ is multi-paradigm...
10 Feb 2023 by CPallini
You have the power of the standard library, at your disposal: us it! See: std::merge - cppreference.com[^]. #include #include #include using namespace std; int main() { vector vec1{3, 5, 7, 12, 16, 19}; ...
11 Sep 2023 by CPallini
With C++ 20, the single line std::erase(shoppingList, choice); would do the trick. See std::erase, std::erase_if (std::vector) - cppreference.com[^].
18 Oct 2014 by CubbiMew
Since data is an out-parameter (you're trying to populate it within genRand and make the result available in the caller, right?), you need to take it by reference:templatevoid genRand(T& data, int size){ ...genRand(smallVector, smallSize);genRand(smallArray,...
5 Jul 2015 by Daniel Pfeffer
I will answer the specific question that you asked (leaving all other errors for you to find).When calling procurarNumeroserie() for the first time, contadorProdutos == 0. This means that the loop is not executed, leaving posicao as zero. The caller sees this as an indication that the...
5 Sep 2019 by Danny96
Hello, I am trying to concat vectors when I get data from cable in my while loop. I search for copy method in C++ array a lot and I saw examples like my code which are supposed to run correct, however I am getting error as in title. I put breakpoints and I observed; ...
7 Feb 2014 by Dave Kreskowiak
Uhhh I hate to tell you this, but that's NOT a vector conversion. Not in the slightest.All you did was read a pixel from the image and wrap it in a LARGE block of what looks like XML text. Yeah, it's no wonder your resulting files balloon to 160MB.The direction you appear to be going...
14 Mar 2015 by Dave Kreskowiak
Google for "C# Triangle Mesh algorithms" and you'll come up with all kinds of examples to do it.
17 Nov 2014 by den2k88
Possibly because when you do thisfor(int j : *i2)there is a hidden cast to the type I2, so when the compiler looks for the vTable he gets the one of the base class.That is, if you take a pointer of a child class and cast it to one of its fathers you get to use their exported vTable....
21 Jun 2016 by Dennis1990
Hi,unfortunately im sitting at this problem for 4hours now, and it drives me crazy:i got an 2 vectors as a members of my class.the firstvector contains structs and the vector with the sorting informations is filled by Enums...
24 Jun 2016 by Dennis1990
thank you for your help.i used the STL Sort Comparision Funciton and could use the Member
19 Feb 2024 by dj4400
Hi all, I want to initialize a vector of vectors in c++ vs2010 I tried to declare a table of doubles double dTable[3][4] = { 1,2,3,4, 5,6,7,8, 9,0,-1,-2}; and then declaring a vector of...
18 Oct 2015 by elGp
Hello there, I have a small project about creating vector shapes and manipulating with them. I stuck at creating a rotation tool. Can someone throw a quick eye at it and give me a hint how to deal with that ?
11 Sep 2016 by Emporea
So i am trying to code a program to sort and list some data. I use a vector with my class so every entry got its own object. But i realized i may want to add more tags/categorys to every entry and to store this new data i need a new variables or new functions in my class. How can i add...
3 Nov 2014 by Eugen Podsypalnikov
// On-Demand Test.cpp :)#include "pegshort.h"#include typedef std::vector vecKeys;vecKeys& GetStaticKeys(){ static vecKeys s_keys; return s_kes;}class Test{public: Test() { GetStaticKeys().push_back(pegshort(3)); }} testIt;
5 Dec 2014 by FoxRoot
Hello everyone,I' am working on vectors. I searched lots of resources. However, there is no data about vectors in C. Basicly, I should create an object(ie. Person) which should be a vector. Each property of actual object should be a vector. Is there any idea or source to read?Thank you.
7 Dec 2022 by Freddie Francis
This method finds all Alien objects in the AlienList object’s Vector whose humanoid field has the value false. It stores all matching Alien objects in a new Vector that is then returned from the method. The method must also remove all the...
30 Jan 2015 by Fredrik Bornander
That's because you create a new vectors in mergesort.In this function;void mergesort(vector& numbers)you're not modifying the contents of numbers, you're creating two new vectors, copying the elements from numbers over to the new vectors.This is why the result is the same as the...
19 Oct 2015 by George Jonsson
Seems like it is not possible to initialize the array the way you are doing it.See this link error C3074: an array can only be initialized with an initializer-list[^]In your case it should be std::vector> cKey { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };or...
23 Jun 2020 by Greg Utas
Replacing its erase() function
12 Sep 2023 by Greg Utas
If the order of elements in the vector isn't important, an efficient way to do this is to move the last element into the slot of the element being erased. This is how I manage the list of open sockets for the poll function, and I wrote a simple...
6 Dec 2015 by Gregory Morse
WRL Collection library ported to native C++
16 Mar 2022 by honey the codewitch
Get your data on, even on platforms without a reliable STL implementation using these simple but critical classes.
15 Jun 2014 by hor_313
HiI've declare a vector like this: Vector vec(3);for(Vector::iterator i=vec.begin(); i
22 Sep 2014 by Igor-84
I use the following code for writing the vector to map container:int my_array[2];my_array[0] = 356;my_array[1] = 41; my_vector.push_back(my_array); std::map*> my_map;my_map.insert(std::pair*> (1, &my_vector));And when I try to...
17 Nov 2015 by ikon95
I'm new to C++ and my question is how can I retrieve an object from the Flight to be compared to the input (flightNumber) in the main? How do I declare the attributes type in the main? The error message displays "invalid conversion of 'int' to 'Flight' in the second last line.class...
12 Jan 2016 by J. Andrzej
Hi,Recently i've found strange error;class ca{public:int m_a;};class cb{public:vector m_v;};CArray my_arr;ca ca_elem;cb cb_elem;my_arr.Add(cb_elem);my_arr.Add(cb_elem);my_arr[0].m_v.push_back(ca_elem); //this line causes crash, i can't...
9 Jan 2015 by JekasG
I have this problem which I have been trying to figure out for quite some time already. The code I have below is almost complete. I just need to add this additional feature it should work how I want it to work.So what I want to implement into the code is the make alertedLock false when...
7 Apr 2017 by Jochen Arndt
There are two errors in your code: You are never calling CreateGrid() (Grid::grid is empty) The Grid::grid vectors are never allocated To fix the first error call CreateGrid() in the constructor: Grid(cv::Mat _map){ map = _map; gridx = map.cols; gridy = map.cols; ...
10 Sep 2017 by Jochen Arndt
There is no clear concept in your code and you are mixing C and C++ library functions for similar tasks (e.g. using C++ and C streams for file operations). I don't see actually where and why your code fails, but here are some tips: Your code does not check for errors. You should check the...
19 Sep 2017 by Jochen Arndt
There are three errors in your code. The first two ones: You have a fixed array size of 10 for row and col but are accessing 11 elements (out of bound access) and did not initialise all elements: for (int i=0; i
3 Nov 2020 by Joe Woodbury
In addition to Richard's solution, I'd: 1) make collection const. void printData(const vector& collection); 2) Iterate the collection using: for (const auto& item : collection) 3) Add void print() const method to CD_TYPE. 4) Use...
18 Oct 2014 by joedoeuse
I am attempting to assign random numbers to some array or vectorWhen I use this method on an array it works fine, however when I use this with an vector, it will not work. // declare small vector vector smallVector(smallSize); // call helper function to put random data in...
11 Dec 2021 by John Brg
I have two vectors A,B and I want to merge them to a vector C but I want to preserve any duplicates in each vector while discarding duplicates between the two. For example if I have A{1,2,3,4,2,5} and B{7,8,2,2,2,3,3} I want C to be...
11 Dec 2021 by John Brg
Well it seems std::set_union does this. Nothing else is needed.
1 Dec 2016 by JohnnyG62
Here is the code I'm trying to compile. I get this error:no matching function for call to ‘std::vector >::insert(int, const char [2])’on this linedataDictionaryEntryFieldsId.insert(2,"B");What am I doing wrong?#include "main.hpp"#include...
1 Dec 2016 by JohnnyG62
I found that erase works it=v.begin() + 1; v.erase(it);
10 Jan 2017 by JohnnyG62
I need to have a vector of a struct. That's easy but when I try to define a iterator for it I get this error on line 23 (the last line where I try to declare the interator)template class std::vector’ used without template parameters. Here is all the code#include...
16 Jun 2014 by Joren Heit
Assuming x and y are accessible as members of your Point type, for (Vector::iterator i = vec.begin(); i != vec.end(); ++i) // srsly, what's with the post-incr in ALL code??{ int x = i->x; // or whatever type it is // do stuff}If your compiler supports the C++11...
15 Oct 2020 by Josh_0101
Hi, I'm trying to define a structure (Brace initialization, has constructor) for a Vector function, but it failed to be compiled and showed these errors. error C2059: syntax error : ',' error C2334: unexpected token(s) preceding '{'; skipping...
22 Sep 2014 by jsolutions_uk
my_array is an array of 2 integer values, 356 and 41, all good so far ;) ...I am assuming that my_vector is declared as a std::vector ? So is a vector of pointers to integers, or in your case, I am assuming you intend it to be a vector of pointers to arrays (or rather a vector of...
13 Aug 2019 by k5054
That should be def.push_back(line). pop_back() deletes the last element of the vector. See vector::pop_back - C++ Reference[^] Additionally map; should be generating a compiler error, as it does not declare anything.
20 Nov 2020 by k5054
You need to tell sort how to compare the two structs. since there's no default comparison for non basic types. Do you want to sort by name or by grade, or by grade then by name, or ...? Probably the easiest way is to add an operator
24 Jan 2023 by k5054
If you are using linux you can approximate a C++ vector using a dynamic memory buffer stream (aka a memstream). Here's an example of how you might go about that: #include #include int main() { int *ints = NULL; /* a...
10 Feb 2023 by k5054
Take a look at the loop inside merge_sorted(): for(int i = 0; i
28 Jun 2023 by k5054
I added a main function the above code vis: // .. QB's code up to here #include int main() { vector test; sort( test.begin(), test.end(), [](const node &a, const node &b){ return (a.distanceToStart
16 Apr 2015 by KarstenK
You can declare some data structure (struct) which holds all of your data. That can be set at thread start or as global data.It is a common practice to use pointers to that data.struct DATA{ std::vector *cluster; int* iteration;};//possible array for 4 threadsDATA...
20 Jun 2016 by KarstenK
To achieve your own sort order you must overwrite the sorting algorithm, by overwriting the comparison operator "
11 Sep 2016 by KarstenK
I think you should do some design wor with UML to clarify what you want to code. Here is a tutorial. An easy solution is also to draw it at paper - best with a pencil.Dont knowing the type of the variables is bad style. You can do such stuff by adding a dictionary which has a key (your...
10 Sep 2017 by KarstenK
the path sound weired: string path = "C:\\Images:\\"; with the second ":" Resolve this and debug the code.Maybe the overloaded call isnt resolved as you wish. Try to rename one function.
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.
3 Oct 2016 by Kishaan Jeeveswaran
I have a vector array of n elements and I let users to enter n number of integers. Now, I want my array to contain only distinct integers. In other words, I want it to remove all the copies of an integer so that the array is left with only one occurrence of every integer. If my vector p =...
3 Oct 2016 by Kishaan Jeeveswaran
Found the solution!I used std::sort(p.begin(), p.end());p.erase( std::unique( p.begin(), p.end() ), p.end() );And it automatically deleted all the copies and gave me the new array size! Thanks for the suggestion guys! :)
15 Dec 2015 by Leo Chapiro
You are just doing this :)Vector already internally dynamically allocates when you push_back into it.If you think about something like vector * pVec = new vector (size);so you don't need it: vector is already a wrapper around the process of dynamic allocating, so...
11 Dec 2017 by Leo Chapiro
Just try to find object vector C++, that's all!
4 May 2014 by leon de boer
This is a complicated task I did the first part of a task in an old articleConnected Component Labeling and Vectorization[^]That creates little line segments that form the connected part of the image but to really do anything useful you now have to run recognition and/or filters on it....
21 Feb 2022 by lock&_lock
I have to make several subvectors with lengths following elements of another vector For example : vector A{2,3} // Vector A has 2 elements, therefore I need to make 2 subvectors A[0] = 2, make a new subvector with length of 2, example : B...
22 Feb 2022 by lock&_lock
(I posted this on CodeReview as well, I hope it's ok. I would love to get different perspectives & suggestion across different platforms). I am following a question on a programming challenge website (here's the original reference). What I have...
30 Jan 2015 by m.r.m.40
Hi,I've written the code below as a merge sort using vectors and it has a problem.I pass the vectors by reference and change them inside the called function and when the caller function uses the vector it's still the same as I entered those numbers into the vectors without any...
4 Aug 2015 by Makhno
Hi all,I'm a new member of code project and I'm not an expert software designer, therefore, please, use a simple language for your answers. Now I'm facing this problem: I have to create a dll which should be used by several clients, using either different compilers or different version of...
19 Jan 2020 by Manujaya Premathilaka
I am writing a program in c++ using eclipse. I have a vector which needs to store pointer objects. When I compile the program, it crashes saying the program has stopped working. How can I fix this error? //declaring pointer to TopStock class TopStock* stock = new TopStock(row[0], row[1],...
10 Dec 2019 by Md Razeenuddin Mehdi
Given a string S with length N. Choose an integer K and two non-empty subsequences A and B of characters of this string, each with length K, such that: >> A=B, i.e. for each valid i, the i-th character in A is the same as the i-th character in B. >> Let's denote the indices of characters used...
4 May 2014 by Member 10793720
As in the title, i need help with making this app.I'm new in c# so i don't really know where to start.I know that there are open source tools for this but problem is i don't know how to use them, for example, Cspotrace. Better would be if this could be done without any outside...
18 May 2014 by Member 10827575
NOTE: This is a repost of my previous question from stack overflow that I am having issues getting an answer for.http://stackoverflow.com/questions/23717167/sfml-program-crashes-when-trying-to-draw-sprite-from-vector[^]I am writing this relatively simple program to fire a small projectile...
28 Sep 2014 by Member 11116263
int main(){ vector readCountryInfo(const string& filename); // Creating empty vector vector myVector; // Opening file ifstream in; in.open("worldpop.txt"); if (in.fail()) { throw...