exdate ExDate 0 7 date c pk notnull
symbol Symbol 8 20 string c sk notnull
factor Factor 21 36 number c no null
This is my Second my file data.(file2.txt)
name Name 0 3 string c pk notnull
symbol Symbol 4 15 string c sk notnull
class Class 16 20 string c no notnull
In my load Function (LoadIndexTable()) I externally calculated every field size and I pushed it into 2D vector .
Now Let me say my problem. After reading file1.txt, I'm getting the below result. Its giving correct output.
exdate ExDate 0 7 date c pk notnull 8
symbol Symbol 8 20 string c sk notnull 13
factor Factor 21 36 number c no null 16
After Reading file2.txt, I'm getting the result not as same ( Wrong at 2nd field ) .This is my output for file2.txt
name 4ame 0 3 string c pk notnull
symbol 12mbol 4 15 string c sk notnull
class 5lass 16 20 string c no notnull
That is the field length which I calculated by my programming is overlapped in my 2nd Field of the 2D vector string. I don't know really why I'm getting this bug. Any one please explain me How to fix this bug.
At a cursory glance, there are a few things you should clean up. In your while loops, you declare a few variables. Since it is a loop, this means that it will declare them multiple times, causing an error. Additionally, you have declared the variable "string s" twice, once in each loop. The variables in question are in bold below:
while (fsIndex)
{
string s;// This is also declared twice, in each loop
fieldIndex=0;
if (!getline( fsIndex, s )) break;
istringstream ss( s );vector <string> record;while (ss)
{
string s;// This is also declared twice, in each loopif (!getline( ss, s, '\t' )) break;
record.push_back( s );
if(fieldIndex==2)
startIndex= atoi(s.c_str());
elseif(fieldIndex==3)
endIndex= atoi(s.c_str());
elseif(fieldIndex==6)
{
if(s.compare("pk")==0)
primaryField=rowIndex;
elseif(s.compare("sk")==0)
secondaryField=rowIndex;
}
fieldIndex++;
}
std::stringstream fLenStream;
fieldLength = endIndex-startIndex+1;
fLenStream << fieldLength;
record.push_back( fLenStream.str() );
indexTable.push_back( record );
record.clear();
rowSize+=fieldLength;
rowIndex++;
}