Following code is giving me RWBoundsErr error
terminate called after throwing an instance of 'RWBoundsErr'
bool filterData()
{
while(!inputFile_.eof())
{
currentLine_.readLine(inputFile_);
//outputFile_<<currentLine_(0,1)<<currentLine_(2,1)<<currentLine_(4,13)<<currentLine_(0,1)<<currentLine_(2,1)<<currentLine_(4,13)<<endl;
outputFile_<<currentLine_[0]<<currentLine_[2]<<currentLine_(4,13)<<currentLine_[0]<<currentLine_[2]<<currentLine_(4,13)<<endl;
}
return (TRUE);
}
But if I use the commented out line instead, everything is working as expected.
currentLine_ is of data type RWCString
outputFile_ and inputFile_ has the path of the inout/output txt files
Sample contents of the text file
ABCD1234567890123 2017/10/16 13:40:28
WXYZ9876543210987 2017/10/16 13:40:28
Please note that there is a trailing space at the end of each line
Even though I have identified the solution to this issue, I would like to understand why this code is failing.
Take a look at the documentation related to
operator<<()operator forRWCString:and
RWFile:There is no
<<operator which would take achar.currentLine_(0,1)is a substring which can be used with<<operatorOn the other hand the
currentLine_[0]is acharIn your case the attempt to use
charwith the<<operator causes theRWBoundsErrerror.