Hi
The following my code snippet

void main() { vector<vector<string> > edge_set_test; [B]edge_set_test[0][0]="1"; edge_set_test[0][1]="0";[/B] cout<<"\nTesting values "<<edge_set_test[0][0]<<" "<<edge_set_test[0][1]; }

While assiging the values to the vector it throws runtime error what can be the reason for this..[code=c++]

void main()
{
vector<vector<string> > edge_set_test;
edge_set_test[0][0]="1";
edge_set_test[0][1]="0";

cout<<"\nTesting values "<<edge_set_test[0][0]<<" "<<edge_set_test[0][1];
}

While assiging the values to the vector it throws runtime error what can be the reason for this..

Your vector doesn't have any elements to assign to. You need to set the initial capacity, or insert new elements with push_back:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
  vector<vector<string> > edge_set_test ( 1, vector<string> ( 2 ) );

  edge_set_test[0][0] = "1";
  edge_set_test[0][1] = "0";

  cout<<"\nTesting values "<<edge_set_test[0][0]<<" "<<edge_set_test[0][1];
}
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
  vector<vector<string> > edge_set_test;

  edge_set_test.push_back ( vector<string>() );
  edge_set_test[0].push_back ( "1" );
  edge_set_test[0].push_back ( "0" );

  cout<<"\nTesting values "<<edge_set_test[0][0]<<" "<<edge_set_test[0][1];
}

Alternatively, you can combine the two:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
  vector<vector<string> > edge_set_test;

  edge_set_test.push_back ( vector<string> ( 2 ) );
  edge_set_test[0][0] = "1";
  edge_set_test[0][1] = "0";

  cout<<"\nTesting values "<<edge_set_test[0][0]<<" "<<edge_set_test[0][1];
}
commented: Nicely Explained +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.