Inserting values to a multidimensional-vector in C++


I've got a minor problem.

I'm using multidimensional-vectors and I want to insert some values to it at a given position. I'm making a sudoku in wxWidgets and i'm getting the tiles the player have put in and wanting to store them in my mVector.

The mVector looks like this.

vector< vector<string> > board{9, vector<string>(9)};

And at first i've added values just like this.

board[row][col] = value;

"value" is a string and row/col are ints.

Is this a legit way of adding values to the mVector? I'm asking this because when I update the board, by doing this above, I for some reason can't run my other functions where i'm solving the board, giving a hint to the board and so on. Before i store the new values to it all the functions works correkt. Do I maby need to use some other type of build in functions for the vector like insert, push_back or something instead?


Since you declared the vector as size 9x9, yes that is a valid way of assigning values.

Otherwise you could declare the board as

vector<vector<string>> board;

Then fill it with

for (int i = 0; i < 9; ++i) { vector<string> row; for (int j = 0; j < 9; ++j) { row.push_back(value); // where value is whatever you want } board.push_back(row); }

But again, once the board is of size 9x9, you can simply assign a value at any cell for example

board[2][4] = "hello";

<a href="http://ideone.com/YJtRuN" rel="nofollow">Working example</a>


  • Incrementing the size of nodes in Cytoscape.js by a specific value
  • How to stop propagating declarations through hierarchical includes?
  • How to copy pandas DataFrame values down to fill 0's?
  • Ignoring certain validation rules with jQuery validate
  • Getting rid of node-jsx
  • Gatttool non-interactive mode --char-write
  • Division in C# to get exact value [duplicate]
  • Must EOT be at the bebinning in the line?
  • Odd function behaviour with Tkinter
  • Create an Event Handler whenever a new Node is added in treeview
  • CRASH: *** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0 .. 9]
  • Many to Many in Linq using Dapper
  • Add Windows Feature from C#
  • iText RadioGroup/RadioButtons across multiple PdfPCells
  • Is there a package like bigmemory in R that can deal with large list objects?
  • Set focus to first invalid form element in AngularJS
  • Git describe fails to return most recent annotated tag
  • SonarQube: Cannot deactivate rule with missing quality profile
  • How do I include a SWC in an AS2 Flash project?
  • How to add a focus style to an editable ComboBox in WPF
  • How do I superscript characters in a UIButton?
  • How to determine if there are bytes available to be read from boost:asio:serial_port
  • Initializer list vs. initialization method
  • How do I change content of ComboFieldEditor?
  • Is my CUDA kernel really runs on device or is being mistekenly executed by host in emulation?
  • Weird JavaScript statement, what does it mean?
  • Do I've to free mysql result after storing it?
  • AT Commands to Send SMS not working in Windows 8.1
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • SQL merge duplicate rows and join values that are different
  • apache spark aggregate function using min value
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • Sorting a 2D array using the second column C++
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal