Questions tagged [2d-vector]

A mathematical entity used to represent a direction in a plane (among other things) and that can be represented as a pair of real numbers. This tags also pertains to all the possible applications and representations of such an entity in a computer language.

A 2d vector is a 2 x 1 matrix (2 rows and 1 column) which has 2 dimensions:

  • A horizontal component (i)
  • A vertical component (j)

Vectors are commonly used in math and also in programming for things like GUI's with moving images (each image could have a position vector and a velocity vector). Vectors are implemented like normal arrays, the i and j components can be changed and indexed in the same way.

144 questions
6
votes
7 answers

Assigning to a two dimensional vector in c++

#include using namespace std; main() { vector > v; for(int i = 0;i < 3;i++) { vector temp; for(int j = 0;j < 3;j++) { temp.push_back(j); } …
problem_solver
  • 77
  • 1
  • 1
  • 3
5
votes
1 answer

c++ How to sort the rows of a 2d Vector, by the values in each rows column

The Aim: I have a 2d vector. I want to sort it by the value in its 4th column. For example I want to sort this vector: vector> vector1 = {{4,3,5,3}, {2,6,3,7}, …
jdough
  • 73
  • 1
  • 1
  • 6
4
votes
2 answers

C++ output 2D Vector

I wrote two for loops and expected to see if they would output every value in a vector called data, but it doesn't work. There is an error relating to data[i].at(j) that I don't quite understand. vector data; //it is filled with some integers…
rrc
  • 275
  • 1
  • 3
  • 7
3
votes
1 answer

Checking for a match in each element of a 2d vector

I'm creating text based TicTacToe in C++ and need to create a function that checks for a win. Right now, I have a vector of all the moves player X has made: std::vector x_vector = {1, 2, 3, 5, 7}; I also have a 2d vector of win…
Max Waters
  • 33
  • 2
3
votes
1 answer

How to memset on 2d vector

So I have a 2D Vector here that I want to assign a value num, I want to see which performs better fill vs memset() as C++ noob, I am actually having problem setting the proper code syntax as I just always get Segmentation fault when I do…
Zambodia
  • 41
  • 1
  • 2
3
votes
1 answer

Sorting a 2D vector of doubles

I have a list of data (in 4 columns) that I would like to sort by a certain column. It was read in from a file to a 2D vector. I the used the std::sort method and wrote my comparator functor. The program compiles and runs, but when I print the first…
3
votes
1 answer

Initialzing a 2d vector in C++

I know that you can initialize a 1d vector with some value in the following way: vector vec(10, 100); //creates a vector of size 10 and each element = 100 Now I would like to do the same thing with a 2d vector. I know the following would give…
Born Again
  • 2,139
  • 4
  • 25
  • 27
2
votes
0 answers

Trying to change a char variable in a 2D vector, which is also a class object. Keep getting "Thread 1: EXC_BAD_ACCESS (code=1, address=0xe)" error

I'm trying to build 2 classes, one that creates a "function" object (Y = MX + B) and another that creates a Graph object, takes the function, and plots every Y value along the graph by inserting x values from -10 to 10 into the function. I have a…
2
votes
3 answers

Unable to create 2D vector in CPP std::vector> by just giving the size

I was creating empty 2D vector in a header file by just providing size but unable to create it. class Grid { public: int rows = 5/0.05; int cols = 6/0.05; std::vector>…
2
votes
1 answer

Printing an std::queue of 2D vector

I'm trying to create a queue of 2D vectors and see the contents of it each time I push a vector. I tried to implement this and print it with the idea of printing 2D vectors in my head. I have also tried some templates online. Apparently, it does not…
kaMOON
  • 105
  • 10
2
votes
3 answers

Can I convert my 1D vector to a 2D vector faster than this?

The question is quite straightforward. After some trials, here is the most efficient code I found: //For the sake of the example, I initialize every entry as zero. vector vector1D(1024 * 768, 0); vector> vector2D(768,…
John Katsantas
  • 571
  • 6
  • 20
2
votes
1 answer

Shrink a 2D-Vector in C++

I want to get into neural networks and that's why I want to write my own C++ matrix class. The problem is that I'm also pretty new to C++ and to keep things simple, I want to use a std::vector instead of an 2D-Array. At the moment my class looks…
Warsakul
  • 25
  • 2
2
votes
1 answer

Why is this program telling me invalid parameter was passed?

Honestly I don't even know what I am trying to do as of now. But I can't go further until I get this function to work, and it throws that exception each time, what is going wrong? The exception is "Unhandled exception at 0x0F61CAB6 (ucrtbased.dll)…
dcalvert
  • 73
  • 1
  • 11
2
votes
1 answer

Outputting a two-dimensional vector in C++

I have been following a tutorial on how to output two-dimensional vector with C++ and arrived at the following code: #include #include using namespace std; int main() { vector < vector < int > > test { { 1, 2, 3, …
2
votes
2 answers

initializing 2d vector using only 1 line c++

I need to be able to initialize a 2D vector of int's in the same line in which I create it. To be more specific, I have to create a 3x2 size 2D vector and set all of it's values to 0 using only 1 line of code. Is there a way this can be done without…
S.Mitchell
  • 91
  • 1
  • 2
  • 10
1
2 3
9 10