I searched everywhere for this, but found nothing... What I need to know is how to insert an integer value in a double vector. In double arrays, we would simply write, for example:
1 2
int array[10][10];
array[0][0] = -1;
I am going to post part of the code, as I am sure that the problem lies in this part only.
This just for initializing the vector...
1 2 3 4
vector< vector< int > > matrix;
vector< int > clause;
for (int j = 0; j < numLit; j++) clause.push_back(0);
for (int i = 0; i < numClause; i++) matrix.push_back(clause);
Now this is how I "tried" to insert into the double vector... But it turned out that my program crashed. I isolated everyline, and the last line in the for loop is causing the program to crash.
1 2 3 4 5 6 7
for (int i = 0; i < varcount; i++)
{
int column = abs(temp[i]);
int row = linecount - 1;
int value = (temp[i] > 0 ? 1 : 2);
matrix[column][row] = value;
}
I repeat my question, how can I insert into a double vector?
while ( !inData.eof() )
{
getline (inData, str);
if (linecount == 1)
{
sscanf(str.data(), "p cnf %d %d", &numClause, &numLit);
for (int j = 0; j < numLit; j++) clause.push_back(0);
for (int i = 0; i < numClause; i++) matrix.push_back(clause);
}
if (linecount > 1 && linecount < numClause)
{
spacecount_ = 0;
for(int i = 0; i != str.size(); i++) spacecount_ += ( str[i] == ' ');
varcount = spacecount_ + 1;
int *temp;
temp = new (nothrow) int [varcount];
tempfile.open("fout.txt");
tempfile << str;
tempfile.close();
int number;
tempfile_.open("fout.txt");
for (int i = 0; i < varcount; i++) tempfile_ >> temp[i];
tempfile_.close();
}
for (int i = 0; i < varcount; i++)
{
int column = abs(temp[i]);
int row = linecount - 1;
int value = (temp[i] > 0 ? 1 : 2);
matrix[column][row] = value;
}
delete [] temp;
in the case where linecount = 0 I WANT to extend the vector to hold 12 elements by 15 elements (number of clauses = 12 and number of literals = 15)... So, basically this if statement will execute once, I tried taking out this:
1 2
for (int j = 0; j < numLit; j++) clause.push_back(0);
for (int i = 0; i < numClause; i++) matrix.push_back(clause);
outside the while loop and punch in 12 and 15 for numClause and numLit respectively, and it worked, but HOW can I inside the loop, while I am reading from a file, resize the double vector?
Thanks!