// Code derived from Stroustrup's PPP2 book// § 11.3.1 File open modes// -and beginning on p 389#include<fstream>usingnamespacestd;intmain(){constchar*name1="myfile1";constchar*name2="myfile2";constchar*name="myfile0";ofstreamof1{name1};// defaults to ios_base::outifstreamif1{name2};// defaults to ios_base::inofstreamofs{name,ios_base::app};// ofstreams by default include// io_base::outfstreamfs{"myfile",ios_base::in|ios_base::out};// both in and outif(!fs){;// oops: we couldn’t open that file that way}ifstreamifs{"redungs"};if(!ifs){;// error: can’t open “readings” for reading}{ofstreamofs{"no-such-file"};// create new file called no-such-fileifstreamifs{"no-file-of-this-name"};// error: ifs will not be good()}}