void Lexicon::addWordsFromFile(string filename)
{
ifstream in;
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(in, line); //read each line
if (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
}
in.close(); //boilerplate close file line
}
this function has several errors
line 4
- C2513: 'std::basic_ifstream<_Elem,_Traits>' : no variable declared before '='
- C2059: syntax error : ';'
- C2143: syntax error : missing ';' before '='
those errors are gone, now I have 16 linker errors - do I need to check if they are related to the new headers or should I just start resolving these as a separate issue?
Also, point me in the right direction to learn what you know about what these are and why they fixed the errors
Referring to Disch's message (http://cplusplus.com/forum/beginner/73146/#msg390750 ).
#define in defines "in" to the preprocessor, it could be assigned a value, making it a constant, like so: #define in 34 .
This would replace every occurrence of 'in' within your code by number 34.
So, if one of your headers already defines "in", and later it is redefined by another header, this causes confusion and breaks stuff.
So, in order to check for its existence you use
1 2 3
#ifdef in //if defined in
#undef in //undefine in
#endif //stop if statement
I dug through the header files and the header files referenced by the header files, and the associated .cpp files, and I do not see #define in - in explorer searched the project file for #define in and did not find #define in
do I need the <fstream> .h and .cpp file or is it already included in the compiler library?
So if you did not find in in this header you can insert suggested check around all other headers in this header. Also usually the error message reports the program line number.
/*
* File: foreach.h
* Last modified on Thu Jun 11 12:04:09 2009 by eroberts
* -----------------------------------------------------
* This interface defines the foreach keyword, which is used to
* simplify iteration. All iterable classes import this interface,
* so clients never need to do so explicitly.
*/
#ifndef _foreach_h
#define _foreach_h
#include "genlib.h"
/* These #includes are for files that contain "in" as a token */
#include <ios>
#include <fstream>
#include <sstream>
/* Redefine the ios constants (one of which is "in") */
staticconst ios::openmode IOS_APP = ios::app;
staticconst ios::openmode IOS_ATE = ios::ate;
staticconst ios::openmode IOS_BINARY = ios::binary;
staticconst ios::openmode IOS_IN = ios::in;
staticconst ios::openmode IOS_OUT = ios::out;
staticconst ios::openmode IOS_TRUNC = ios::trunc;
/*
* Class: FE_Iterator
* ------------------
* This class is a base class for all Iterators that can work with
* the foreach construct. The only purpose of this class is to make
* it possible to freeing the iterators after they are no longer needed.
*
* Note: FE_Iterator is implemented in lexicon.cpp, which is the only
* iterable class that is not a template class.
*/
class FE_Iterator {
public:
FE_Iterator();
~FE_Iterator();
};
/*
* Class: FE_State
* ---------------
* This class is used to maintain the state of the foreach processing.
* The class itself is essentially private, but the implementations in
* the different classes use the fields directly.
*
* Note: FE_State is implemented in lexicon.cpp, which is the only
* iterable class that is not a template class.
*/
class FE_State {
public:
int state;
FE_Iterator *iter;
FE_State();
~FE_State();
};
/*
* Macro: foreach
* Usage: foreach (type var in collection) { . . . }
* -------------------------------------------------
* Provides a much simpler hook to the iterator facility.
*/
#define foreach(arg) \
for (FE_State _fe; _fe.state < 2; ) \
for (arg.foreachHook(_fe); _fe.state++ == 1; _fe.state = 0)
#define in =
#endif
also, the foreach.h file does not have a .cpp - why?