Beispiel #1
0
bool extract_tokens_from_file(std::string file_name, evl_tokens &tokens) { // use reference to modify it
	std::ifstream input_file(file_name.c_str());
    if (!input_file){
        std::cerr << "I can't read " << file_name << "." << std::endl;
        return false;
    }
	tokens.clear();
	std::string line;
    for (int line_no = 1; std::getline(input_file, line); ++line_no){
		if (!extract_tokens_from_line(line, line_no, tokens)) {
			return false;
		}
	}
	return true;
}
// This function extracts a line at a time from the input file and passes it to the function "extract_tokens_from_Line();
bool extract_line_from_File(string filename, evl_tokens &tokens)
{
	ifstream infile(filename.c_str());
	
	// This checks whether the input file can be opened. It returns an error if not.
	if (!infile)
	{
		cerr << "This file cannot be opened!" << endl;
		return false;
	}
	
	tokens.clear();
	string line;
	
	//This for loop extracts a line from the input file with each iteration.
	for (int line_index = 1; getline(infile, line); line_index++) 
	{
		if(!extract_tokens_from_Line(line_index,line,tokens))
		{
			return false;
		}
	}
	return true;
}