Most voted "vector" questions
In C++ the Std::vector container is an array and generalizes the concept of a vector. It can be accessed through indexes for the elements as well as in C (through a proper operator overload) and its memory is allocated contiguously. However, unlike an array, the container size is dynamic with automatic management and there is greater flexibility to add elements.
Learn more…78 questions
Sort by count of
-
20
votes2
answers1354
viewsIn which situations should I dynamically allocate a vector to C++?
I’m fiddling with a code from a framework for my work. In one of the functions, it dynamically allocates a std::vector, makes a copy of each node the object has and returns it to the user:…
-
8
votes1
answer290
viewsManipulation of Vectors in C++
Is there a problem if I walk through one vector picking up the size of it with vector size.() and then make a for about the vector? I’m asking this question because almost every time I see…
-
8
votes2
answers2706
viewsHow to use vector to store a class?
Example: class Nome {private: string nome; public: Nome(string nome); virtual void exibirNome() =0; }; class SobreNome: public Nome {private: string nome; public: SobreNome(string nome, string…
-
7
votes1
answer2667
viewsHow does it work to use a vector of type struct ? (C++)
I would like help to understand how it works to declare a vector of type struct. In the example of the code below I create the struct configcarros and I would like to create a vector of the type of…
-
6
votes3
answers844
viewsSorting of object vectors
I am making an application that sorts an object vector. These objects are Cartesian points, defined in the following class: class CartesianPoint { private: int x; // Coordinate X of a pin or a wire…
-
6
votes2
answers602
viewsDifference in C/C++ array declarations
What is the difference and impact that each of these 3 vector statements bring to my code? int n; cin >> n; int* arr = new int[n]; int n; cin >> n; int arr[n]; int n; cin >> n;…
-
5
votes2
answers1246
viewsHow to add elements at the "x" position of an Std::vector
How to proceed to add an element at the position I specify in a std::vector? Not to delete what you already have, but to add in the middle. Here’s an example: Let’s assume that inside a std::vector…
-
5
votes3
answers14329
viewsHow to use the C++ vector class?
Necessarily need the library #include<vector.h> To raise it vector <int> c; Question: How to store values in it and read them?
-
4
votes1
answer68
viewsProblems to remove vector node
I have two classes: class CAlbum { private: QString Nome; /**< Nome do Álbum */ QString Descricao; /**< Descrição do Álbum */ QString Diretoria; /**< Diretoria onde se encontra o Álbum */…
-
4
votes1
answer259
viewsproblem with vectors in android studio
I’m having trouble inserting vectors in android studio my project was created in api21 (5.0), I am testing on a 7.0 device and this is all ok , working perfectly, but an error occurred when running…
-
3
votes1
answer294
viewsMake SVG responsive
I cannot manipulate the size of this Hexagon, I wish it initially had the size of 165x165px, and respectively make it responsive. I don’t have much experience with SVG. <svg width="165"…
-
3
votes1
answer193
viewsDifference between pointer vector for a class and vector for a class?
When is pointer to class will we have to allocate memory space? What is the difference between the following two statements and when they should be used ? Vector <class*> nameOfVector; Vector…
-
3
votes1
answer131
viewsVariable type of return
I want to do functions with variant input type, like this: int count(vector<auto> base, auto val) { int sum= 0; for (auto it : base) { if (it == val) { sum++; } } return sum; } or this: string…
-
3
votes0
answers35
viewsThe Handle function is not converting - Matlab
Hello, I’m getting this mistake: Conversion to function_handle from double is not possible. I have already searched for the bug and tried to change the code but without success. Could you give a…
-
3
votes2
answers59
viewsWhat is the usage limit of . push_back()?
I use a lot .push_back(element) when I’m working with vector, but I don’t know what’s the most elements I can add to a vector before it overflows and performs the reallocation of a new space in…
-
3
votes2
answers447
viewsLimit, or capacity of a Vector
Imagine you ask "when the capacity reaches the limit you should warn the user" I have an integer vector with 15 positions, and the user will enter values inside, the goal is to warn when to reach…
-
3
votes3
answers400
viewsHow to return 2 vectors of different types in C++
I perform a calculation and my result is saved in a vector<int> and a vector<string> How do I make my function return these two parameters in mine main()? int cracking(string chemform) {…
-
3
votes1
answer68
viewsError in Lexing a Mathematical Equation
I’m doing a C++ equation interpreter and I’m trying to show the type of the symbol. But I’m in trouble. I don’t know what’s wrong. Any constructive tips are welcome. main.cpp: #include…
-
2
votes1
answer61
viewsTake all elements that meet a condition
I have some Vector: public static Vector<Integer> id = new Vector<Integer>(); public static Vector<String> nome = new Vector<String>(); public static Vector<String>…
-
2
votes1
answer110
viewsPrinting a vector... Differences between C++ and C... Where did I go wrong?
I’m having problems printing vector structs in C, in C++ it worked... First I will show the version in C with problems (in the execution because compiles without errors) CACHE cache =…
-
2
votes1
answer1154
viewsVectors - Separate negative and positive
I have to make a program that receives a vector of 8 numbers and returns 2 vectors, the first with the positive numbers of the vector of 8 positions, and the second with the negative numbers. THE…
-
2
votes1
answer34
viewsR <- Vector - Error in c(vector_item, v$Qty) : Object 'vector_item' not found
A simple doubt, How to have the (new) vector briefly to avoid: for(v in i$checkout) { c(vector, v$name) -> vector c(vector_item, v$qty) -> vector_item } Error in c(vector_item, v$Qty) : Object…
-
2
votes2
answers71
viewsHow to use comparison function on a Std::Sort
In the code below the program must order the vector campanha based on the number of votes of each councilor: #include <iostream> #include <vector> using namespace std; struct Vereador {…
-
1
votes1
answer73
viewsIs it possible to create an Std::list with an initializer_list?
I’d like to pass one std::list temporary to a function, but do not know if it is possible to do it. I know it is possible to pass a std::vector temporary with a initializer_list: #include…
-
1
votes1
answer68
views"no overloaded Function takes 0 Arguments" when trying to insert into Std:
bunny is the standard class that has only the bunny(construtor) and ~bunny(desconstrutor) pattern. int main() { vector<bunny> bunnies; // Este usa o construtor padrão. bunnies.push_back(); //…
-
1
votes2
answers163
viewsConverting a vector<struct> to C++ into C
I am trying to adapt a C++ function into pure C. I have changed the variable names and structs because it’s beside the point. typedef struct struct1 { int a; int b; int c; string d; } STRUCT1;…
-
1
votes1
answer4452
viewsWhat is the correct way to remove a vector element? C++
Could the way be the same to erase an integer vector, or an object vector? Every time an element is deleted, the vector position has to be changed ? The situation is the same by eliminating at the…
-
1
votes1
answer593
viewsRead from a txt file via fscanf using vector
I have the following while(!feof(f)){ (*ptr).push_back(carro()); fscanf (f, "%d", (*ptr)[add].id); fscanf (f, "%s", (*ptr)[add].marca); add++; } Where *ptr is &vector, a vector of a car struct,…
-
1
votes1
answer388
viewsUse of Thread in c++
I created a code to check the prime numbers, but I’m trying to use the core of my processor to calculate them. #include <iostream> #include <Windows.h> #include <vector> #include…
-
1
votes1
answer15660
viewsPython, ascending order of numbers
My goal in the code is to print an increasing order of integers. For example: User type 2 numbers and I want to print the ascending order. Ex.: n1 = int(input('Digite um número')) #O usuário digitou…
-
1
votes1
answer275
viewsHow to put classes inside vector and manipulate variables with push_back?
It’s definitely something simple, but I researched and didn’t understand how to do. If I have for example the following class, with two variables: class x { public: int var1, var2; }; I want to…
-
1
votes1
answer232
viewsLawtex - how to use logic based on the field of a struct vector?
I have a vector that uses a struct with several variables and one of them is a boolean. What can I do to execute something if at least one element of this vector has this variable as true?…
-
1
votes2
answers91
viewsIs it possible to assign the first column of a row of a/a vector/matrix?
taking as an example a two-dimensional vector of the type char 2x2: char vet[2][2]; Is it possible to assign to the first line indices of this vector? or they work like a pointer to the other rows…
-
1
votes4
answers1763
viewsHow to know which is the largest variable of a vector in R?
Suppose I have the following variables: x = 2 y = 3 z = 5 And turn them into a vector: vetor = c(x,y,z) I thought I’d use the function max: max(vetor) [1] 5 But if I use the function max returns a…
-
1
votes2
answers41
viewsWhen I try to display the values of a vector some more zeroes appear
I want to display some values of my vector, but before displaying the values are appearing some zeros. #include <iostream> #include <vector> using namespace std; int main(){ int…
-
1
votes0
answers397
viewsComparison of matrix and vector C/C++
I need to compare a user-inserted op vector with the top 10 columns of each row of a 12x12 array. for(k=0; k<10; k++){ for(i=0; i<12; i++){ for(j=0; j<10; j++){ if(op[k]==d[i][j]){ if(i==1)…
-
1
votes1
answer100
viewsC++ Reach Problem
I’m a beginner in C++ programming and came across a problem when trying to execute my code on Atom, using the gpp-Compiler package and Mingw: 'Function' was not declared in this Scope (l.8). I…
-
1
votes0
answers91
viewsWhat is the Bubble short error in this code?
I tried to solve this problem of URI Online Judge and I came to this code, and it works for test cases smaller than the problem, and I’ve already looked for the bug, only I can’t find it. Code:…
-
1
votes1
answer172
viewsHow to access elements of a vector of a type defined by struct?
In my code, I made the following statement of struct: struct material { int idmaterial; double rho; double precokg; }; I wanted to run this function, which reads data from a file:…
-
1
votes1
answer31
viewsvector inside vector generates double values in the second dimension
In the example below (which can also be seen in Ideone), I have a vector of a class and within the class I have an element too vector. The point is that by doing the push_back class, the internal…
-
1
votes1
answer178
viewsTake the result of an expression in c++
I’m almost done with my expression interpreter. But I have no idea how to do the most important part : The result I’d learn a lot from any idea. main.cpp #include <string> #include…
-
1
votes1
answer46
viewsCheck if a certain value is in the vector
I created the vector fragil that will accept various inputs from the user, inputs that will (or will not) be the position of other elements in another matrix. I used the following function to create…
-
1
votes0
answers2440
viewsHow to count repeated values within a Javascript array
I am learning in Rra Javascript, but I came across a situation that I could not solve. I’m looking to create a chart where The horizontal line will be the date (I’ve already managed to eliminate the…
-
1
votes1
answer252
viewsC++ free(): invalid aborted when trying to create a function
I am trying to create a library for operations with matrices in C++ but am running into a problem. I created a function to print on the screen a certain matrix. The function even returns the…
-
0
votes1
answer744
viewsVector class and random numbers in C++
The function only returns me the memory address, how do I make it return the content and not the memory address? #include <iostream> #include <time.h> /// por causa de srand() #include…
-
0
votes3
answers156
viewsANDROID - ERROR: Unchecked cast: java.lang.Object to java.util.vector
I’m trying to fill a spinner city according to the state selected in another spinner via webservice. But this giving an error in this line in the class usuarioDAO. Vector<SoapObject> resposta…
-
0
votes1
answer539
viewsClass c++ has no Member named
I’m starting to develop a list list to represent a graph in memory. I’ve only done that first part and I’m getting the following mistake: class std::vector<No> has no member named 'getId'…
-
0
votes1
answer292
viewsProblem with vector function in C++
Hello, I’m trying to make a matrix calculator and my idea would be that the user entered with the number of rows, columns and soon after with the matrix elements, the problem is that when I write…
-
0
votes1
answer67
viewsHow do Overload the assignment operator into a class that contains vector?
I would like to do the allocation operator’s Overload (operator=), I know I have to reserve memory, and copy data from one to the other, however I do not know how to copy one vector to the other…
-
0
votes1
answer543
viewsTake only equal elements in a matrix
I have a matrix for example: 1 4 7 1 3 4 6 7 1 2 3 4 5 6 I have to see the repeating numbers in ALL lines, in the example, the numbers should be the result: 1 and 4. For it is they who repeat in all…