G’ayri oddiy holatlarni generatsiya qilish
G’ayri oddiy hodisalarni generatsiya qilish uchun throw operatoridan foydalanish lozimdir. Misol uchun
void file_copy(char *source, char *target)
{
char line[256];
ifstream input_file(source);
ofstream output_file(target);
if (input_file.fail())
throw(file_open_error);
else
if (output_file.fail()) throw(file_open_error);
else
{
while ((! input_file.eof()) && (! input_file.fail()))
{
input_file.getline(line, sizeof(line)) ;
if (! input_file.fail()) output_file << line << endl;
else throw(file_read_error);
if (output_file.fail()) throw (file_write_error) ;
}
}
}
Dasturda ma'lum g’ayri oddiy holatlarni generatsiya qilish uchun throw operatoridan foydalanilgan.
Dostları ilə paylaş: |