All pastes #26373 Raw Edit

Unnamed

public text v1 · immutable
#26373 ·published 2005-10-23 14:58 UTC
rendered paste body
/**
 * Parses from a given fileInputStream and reinitializes this student.
 * Expecting \t as sepeartor between the values and \n between students.
 * Reads only one student
 * @param istr InputStream to read from.
 */
void Student::readf(istream& ifstr) {
	
	// fetch block-wise
	char* buffer = new char[64];
		
	// read block
	ifstr.read(buffer, 64);
	
	string* data = new string[4]();
	
	unsigned int stopIndex = 0;
	unsigned int startIndex = 0;
	
	string carry();
	
	for (unsigned int i = 0; i < 4; i++) {
		
		while (!ifstr.eof()) {
		
			string input = buffer;
			input.append(carry);
			
			startIndex = stopIndex;
			if (i == 4) {
				stopIndex = input.find_first_of("\n",startIndex);
			} else {
				stopIndex = input.find_first_of("\t",startIndex);
			}
			
			if (stopIndex != string::npos) {
				data[i] = input.substr(startIndex, stopIndex);
				carry = string();
				input = string();
				stopIndex = 0;
			} else {
				carry.append(buffer);
			}
			
		}
	}
	
	regNum = parseRegNr(data[0]);
	fname = data[1];
	lname = data[2];
	birth = data[3];	
			
	free(buffer);
	
}