I have a series of datasets that I load like this:
ifstream code that looks like this in the beginning of main
Code:
int main
{
vector<vector<bool >> setbool;
ifstream setboolCSV ("setboolcsv.csv");
linenum = 0;
itemnum = 0;
while (getline (setboolCSV, line))
{
++linenum; //increment the line count
setbool.resize(linenum);
istringstream linestream(line);
itemnum = 0;
while (getline (linestream, item, ','))
{
++itemnum; //increment the item count
setbool[linenum-1].resize(itemnum);
const char *pitem = item.c_str();
doubleitem = atof(pitem);
setbool[linenum-1][itemnum-1] = doubleitem;
}
}
setboolCSV.close();
...
return 0;
}
end of code
however classes that I create will be reliant on values in setbool based on indexes that i create. Is there a way to create bool before main, but pass it into main as well as any class header files that i create? what i am trying to avoid is if I have 10 classes that uses setbool[X][Y] to make a decision, i don't want to create 10 instances of setbool.
this code works as is - any thoughts also on how to structure to clean up main ? i realize that it is not best to convert from double into bool, but it is ok b/c my file is 1s and 0s. 0s will turn into false, 1s into true. if there is better way to write please let me know.