Click here to Skip to main content
15,867,308 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 Score

Vector 

27 Apr 2016 by Clayton Rumley
There are those who think I am crazy, and this just might be the proof.
4 Sep 2023 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
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.
29 Jun 2016 by The Zakies
we would create Hand_tool to pan through the drawing form, and we would use a custom cursor of open and closed hands
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,...
11 Dec 2015 by Sergey Alexandrovich Kryukov
Probably this is because you act in identical way: create the brand new rd and genEngine objects each time you need a random value. You need to create and initialize these objects only once in the whole life cycle of your process. For example, create such objects in main and pass the pointer to...
6 Sep 2020 by Издислав Издиславов
Showcase for simple techniques for XAML button styling
10 Feb 2023 by k5054
Take a look at the loop inside merge_sorted(): for(int i = 0; i
11 Sep 2023 by Rick York
That is done use the erase method of the vector class : https://cplusplus.com/reference/vector/vector/erase/[^]. It can be a very expensive operation to perform if deleting from anywhere except the tail end of the vector. If deletions are going...
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....
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; ...
6 Sep 2019 by Stefan_Lang
The function GetIntArrayFromCharArray creates a copy, therefore your calls to begin() and end() refer to two different arrays! This is reflected literally in the error message - all you need to do is read and understand it. ;-) [..] (cut away revised parts of the solution - see below) ...
3 Nov 2020 by Richard MacCutchan
You are trying to pass a vector reference to the printData function, so you should use the correct declaration: void printData(vector& collection); Also in your printData function you are trying to print 5 entries, but the...
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
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 ...
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 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 =...
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...
20 Jun 2016 by KarstenK
To achieve your own sort order you must overwrite the sorting algorithm, by overwriting the comparison operator "
8 Jun 2017 by OriginalGriff
Compiling does not mean your code is right! :laugh: Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email contained the message you wanted to send. So stop...
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}; ...
9 Feb 2024 by Nicolas DESCARTES
What are vector databases?
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 */ ...
20 Feb 2024 by merano99
The problem is probably that Visual Studio 2010 does not support C++11 initialization lists for vectors. Although I cannot test with VS2010, I could imagine that this task could be solved with a template function. Here, a two-dimensional vector...
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...
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...
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
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;
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...
30 Jan 2015 by nv3
You probably meant to write:void mergesort(vector& numbers){ { ... numbers = merge(halfone, halftwo); } }But let me tell you that copying those vectors back an forth will make it a really inefficient way of sorting. Instead of copying vectors you...
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)...
15 Dec 2015 by User 59241
From your example I am guessing you are asking how to construct the vector of unique_ptr's to Elf and populate. Like so: vector> vec_uniqptrElf; for (auto i = 0; i (new Elf(90))); }
19 Dec 2015 by OriginalGriff
"What are those type of logo's called?"A logo. It's just been embossed into the medium when it was printed. Talk to your printing company and they can give you the additional pricing."is it possible to create them in Photoshop?"Yes.
23 Apr 2016 by Patrice T
for(int a = 0; a print();}Are you sure this loop don't miss the last place in the vector ?[UpDate]Quote:It goes from zero to size - 1your code stops before size-1, so it stops at size-2, check again.
23 Apr 2016 by Philippe Mori
You probably want to docout print()
5 Apr 2017 by Stefan_Lang
Quote: What is the different between these two? The first is a vector of (smart) pointers to elves and the second is a (smart) pointer to a vector of actual elves. You could compare the first to a sign pointing to a chest of drawers with an elf sitting in each drawer (basically a large...
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; ...
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
11 Dec 2017 by Leo Chapiro
Just try to find object vector C++, that's all!
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. ...
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.
9 May 2018 by Richard MacCutchan
You have not explaine the problem. Although I suspect that your class declaration entry for Borrow1 is wrong. You have the following in your class: public: Album(); void Borrow1() {}; // Borrow1 is an empty function. }; And you later define Album::Borrow1() with a proper body. In my test this...
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.
15 Oct 2020 by Richard MacCutchan
That syntax is in a later version of the compiler than the one provided by VS2008. You should upgrade to VS2019.
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...
3 Nov 2020 by CPallini
You could also overload the insertion 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...
3 Jul 2016 by The Zakies
we will continue the functionality of the hand tool with having a navigator panel which works as a map, we will also have a red rectangle which tells the user where he is actually viewing inside the whole form, also it can be moved to pan the form
13 Aug 2023 by merano99
It seems to me that templates might not be the right way for the desired functions. I would first overload only the output operator. There are several ways to do this. Instead of the function as before, a class VectorPrinter can be created that...
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[^].
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...
7 Feb 2014 by SoMad
I agree with Sergey and Dave - you are going about this the wrong way. I am not sure exactly what you are trying to accomplish, but I think you would be better off inserting an tag in your SVG and either link to the image file or possibly base64 encoding the image and embedding that in...
13 Mar 2014 by Venkat Raghvan
Hello,I read one csv file in which it contains different types of data like string, integer etc.I want to fetch only integer data from that file and store in vector.Below i copy some code that read line from file,store in vector.I tried to convert string to integer or double and do some...
13 Mar 2014 by vikram_bullet
Venkat When you access the csv file your first value is Employee Code, thus we can assume a relationship as First Value -- Employee Code 2 Value -- Employee Name 3 Value -- Date and so on to 8 Value -- Status So every 9th position after the first is your Employee Code....
14 Mar 2014 by Orjan Westin
My first question is how the data file continues. Does it continue with another three-line entry for another employee, or does it continue with further dates for the same employee (i.e. there is only one employee per file)?Either way, you'll have to parse the string you read in. I wrote a...
15 Jun 2014 by hor_313
HiI've declare a vector like this: Vector vec(3);for(Vector::iterator i=vec.begin(); i
31 Jul 2014 by WENzER
I am trying to write a program in C++ which should input a string array, and string should contain Employee Name Salary and Its Manager Name with comma seperated delimeterThe input will be provided following format:Mr XX, 5200000, NONEMr YY,52000, Mr. XXMr ZZ, 34500, Mr. YYThere is...
30 Jul 2014 by chandanadhikari
hi,for simply comparing 2 vectors you can check this out [^]hope it helps !
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...
17 Nov 2014 by nashi
I have Iterator template for class and class for use in the for statement.templateclass Itr2 {public: Itr2() { } ~Itr2() { } typedef typename Itr2 type; typedef typename T& reference; virtual type& operator++() { return *this; } virtual T& ...
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....
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...
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...
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.
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...
21 Mar 2015 by Member 11544807
Hi guysmy problem is to convert bitmap to SVG in c#. I found something like this http://docs.opencv.org/2.4.2/doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.html but this didn´t solve my problem. I need to convert for example a facewith white background from bitmap to...
21 Mar 2015 by OriginalGriff
We aren't going to be able to give you an "out of the box" solution: this is not a trivial process in any way, shape or form.The problem is that Bimap, JPG, PNG, etc. files are raster graphics: they store a fixed array of pixels in various shades of red, green and blue (or hue, lightness and...
21 Mar 2015 by phil.o
SVG being an xml-based format, if you do not want to use xml, you are going to have quite a hard time :)The following post on SO could perhaps shed a light on your requirement:SO: Convert Image (JPG,BMP,GIF) to SVG[^]
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...
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...
21 Apr 2015 by nizam qbixx
Hi..I was doing a research related to speech recognition. So far I already able to convert a sample waveform (.wav format) to a feature vector by using MFCC which generate .mfc file. I also able to read the .mfc file but I dont know how to related it to the spectogram. Actually, I'm not sure...
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...
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...
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).
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...
19 Oct 2015 by Mạnh Lê
Hi guy !I want to create a vector of arrayvector cKey;BYTE keyTemp[6];memset(keyTemp, 0xFF, sizeof(keyTemp)); // Key is FFF...FFcKey.push_back(keyTemp);but, push_back function is show errorError C3074: an array can only be initialized with an initializer-listHow to...
20 Oct 2015 by Member 4581741
I have used Raphael to create a map. The map uses VML as a base for creating graphics. (http://raphaeljs.com/world/world.js) Ex: AE:...
20 Oct 2015 by Mạnh Lê
vector cKey; // Change hereBYTE keyTemp[6];memset(keyTemp, 0xFF, sizeof(keyTemp)); // Key is FFF...FFcKey.push_back(keyTemp);
29 Oct 2015 by Member 4581741
Nevermind, i was able to convert the latitude and longitudes to pixels(points) and convert that into SVG format.Thanks
31 Oct 2015 by Stefano Lodico
I'm sorry for my bad English, but it isn't my language.I've done an exercise in C++11 for University:This is a program for understanding Templates:#include #include #include class matrix{ public: matrix(int riga, int colonna){ ...
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 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 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 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...
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...
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! :)
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...
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...
10 Jan 2017 by Richard MacCutchan
Your declaration of the iterator is wrong, it should be: vector::iterator FieldsResultsit;// not // vector::::std::iterator FieldsResultsit;
2 Feb 2017 by Richard MacCutchan
You need to fix the code in two places.1. Fix the API so it returns a recognizable value when an input has no outputs. The obvious value being NULL.2. Fix your main code so it recognizes the 'no output' value and writes the blank line, or whatever else you desire.
5 Apr 2017 by Theo Buys
#include #include class Elf { private: int _health = 0; public: Elf(const int &health){ _health = health; } int getHealth(){ return _health; } }; void Test() { using namespace std; auto elves = make_unique>(10000, Elf(90)); int out; for (auto i = 0; i...
7 Apr 2017 by Member 12157883
I am building a search algorithm using OpenCV Mat where I convert the Mat to gray image and then check the pixel to sign it to walkable or not walkable with their coordinate. I used a 2D vector to create a grid of node. The Node is a class to contain information about the pixel. when I try to...
31 Jul 2017 by Member 13338695
#include "stdafx.h" #include #include #include #include #include #include #include #include using namespace std; class Medicine{ private: string productName; double productPrice; public:...
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 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...