That is not doing what you think. invector is a pointer (to a vector<vector>) so 'i' is not indexing your vector as you are trying to do... instead, it's indexing the POINTER (ie: accessing invalid/nonexistant objects)
This would actually need to be for(int j = 0; j < (*invector)[i].size(); ++j){
OR you could make your life easier / less error prone and pass by reference instead of by pointer:
#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
void ProcessInput(constchar *, vector<vector<int>> invector);
int main()
{
char inCharArry[100];
int iRow = 5;
int iCol = 5;
vector<vector<int>> inVec(iRow, vector<int>(iCol));
for (int i = 0; i < inVec.size(); ++i){
for (int j = 0; j < inVec[i].size(); ++j){
inVec[i][j] = iRow;
}
}
cout << "Calling function ProcessInput()" << endl;
ProcessInput(inCharArry, inVec);
cout << "Back from function ProcessInput()" << endl;
return 0;
}
void ProcessInput(constchar inChar[], vector<vector<int>> invector)
{
usingnamespace std;
vector<vector<int>> ivTemp = invector;
for(int i = 0; i < invector.size(); ++i){
for(int j = 0; j < invector[i].size(); ++j){
cout << invector[i][j] << " ";
}
cout << endl;
}
cout<< "In function ProcessInput()" << endl;
}
But i have one more question.
As I mentioned above, I need to do
1. read text data, which is actually adjacency list representing a graph.
2. store the graph representations with zeros and ones (zero means there is no edge, one means there is an edge) to a certain data structure.
In that case, is 2D vector a good approach? I could do it with Matlab and it wasnt that difficult but with c++ it is a different story. Any suggestion would be appreciated!
Also why are you making a copy of the vector (ivTemp)?
Anyway, as for whether or not it's a good approach. That depends on who you ask. Personally I'm not a fan of using 2D anything for gridlike structures. I wrote a biased article on the subject here: http://cplusplus.com/forum/articles/17108/