1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
   | int File::read(int lineNumber, int & sortie) throw(out_of_range) {
	if(lineNumber >= (int) m_lines.size()) throw out_of_range("out of range");
	try {
		sortie =fromStringTo<int>(m_lines.at(lineNumber));
	} catch(BadConversionError &e) {
		cerr << "You must clean the file before reading." << " (int)"<< endl;
		cerr << e.what();
		return FAIL_READING_CONFIG;
	}
        return SUCCESS_READING;
}
 
template<typename T>
static T fromStringTo(string const& s, bool failIfLeftoverChars = true) throw(BadConversionError&){
	T x;
	istringstream i(s);
	char c;
	if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
		throw BadConversionError(s);
	return x;
} | 
Partager