/add words from file into lexicon
void Lexicon::addWordsFromFile(string filename)
{
ifstream ios::in;
ios::in.open(filename.c_str());
string line; //read in line
//opens xml text file and reads in activity code, location and date fields
while (true) {
getline(ios::in, line); //read each line
if (ios::in.fail()) break; //boilerplate check for error
line.erase(0, 1); //remove first tab
if(line == "</ScheduleTasks>") break; //check for end of document
//add readin of location codes and locations to vector array for matching later
line.erase(0, 1); //remove second tab
if(line.substr(1, 15) == "ScheduleTask ID") //look for activity
add (line.substr(42,16)); //store activity code
line.erase(0, 2); //remove third and fourth tab
if(line.substr(1, 17) == "Timing LocationID")//look for location
add1 (line.substr(19,16)); //store location code
line.erase(0, 1); //remove fifth tab
if(line.substr(1, 13) == "Planned Begin") //look for dates
add2 (line.substr(17,26), line.substr(41,50)); //store start date yyyy-mm-dd and store finish date yyyy-mm-dd
}
ios::in.close(); //boilerplate close file line
}
void Lexicon::addWordsFromFile(string filename)
{
ifstream ontology;
ontology.open(filename.c_str());
string line; //read in line
//opens xml text file and reads in activity code, location and date fields
while (true) {
getline(ontology, line); //read each line
if (ontology.fail()) break; //boilerplate check for error
line.erase(0, 1); //remove first tab
if(line == "</ScheduleTasks>") break; //check for end of document
//add readin of location codes and locations to vector array for matching later
line.erase(0, 1); //remove second tab
if(line.substr(1, 15) == "ScheduleTask ID") //look for activity
add (line.substr(42,16)); //store activity code
line.erase(0, 2); //remove third and fourth tab
if(line.substr(1, 17) == "Timing LocationID")//look for location
add1 (line.substr(19,16)); //store location code
line.erase(0, 1); //remove fifth tab
if(line.substr(1, 13) == "Planned Begin") //look for dates
add2 (line.substr(17,26), line.substr(41,50)); //store start date yyyy-mm-dd and store finish date yyyy-mm-dd
}
ontology.close(); //boilerplate close file line
}
but changing the foreach.h file and commenting the line //static const ios::openmode IOS_IN = ios::in;
It's there because someone was trying to be cute and redefine the C++ language by abusing macros. This is always a bad idea because it leads to problems like the ones you are having now.
Someone wanted to make C# style foreach loops in C++, and to do that, they tried to hijack 'in' and make it a keyword.
It was foolish. Whoever did it should be ashamed of themselves.
and why i should comment it out.
Because that #define is polluting the namespace, replacing all instances of 'in' with '='.
Unless you are using 'in' for the purpose of writing those foreach loops, that #define is of no value to you, and it is just wrecking other areas of your code. So it should be removed.
/*
* Method: iterator
* Usage: iter = bst.iterator();
* -----------------------------
* This method creates an iterator that allows the client to
* iterate through the elements in this binary search tree. The
* order of elements produced by the iterator is that of an InOrder
* walk of the tree.
*
* The idiomatic code for accessing elements using an iterator is
* to create the iterator from the collection and then enter a loop
* that calls next() while hasNext() is true, like this:
*
* BST<string>::Iterator iter = bst.iterator();
* while (iter.hasNext()) {
* string key = iter.next();
* . . .
* }
*
* This pattern can be abbreviated to the following more readable form:
*
* foreach (string key in bst) {
* . . .
* }
*
* To avoid exposing the details of the class, the definition of the
* Iterator class itself appears in the private/bst.h file.
*/
Iterator iterator();