Liste des Groupes | Revenir à cl c |
The original code:
>
if (FILE* f = fopen("file.txt", "r"))
{
/*...*/ fclose(f);
}
>
doesn't allow for taking some non-trivial action of the fopen() call
fails, but if a declaration in an if condition is visible in the else
clause, you could write something like:
>
if (FILE* f = fopen("file.txt", "r")) {
/*...*/
fclose(f);
}
else {
perror("file.txt");
exit(EXIT_FAILURE); // or try something else
}
Les messages affichés proviennent d'usenet.