
680 Applications with Files
if (argc<3 )
{
cout<<“Insufficient Arguments”;
exit(1);
}
in.open(argv[1],ios::in | ios::nocreate);
if (in.fail())
{
cout<<“\nFile Not Found”;
exit(0);
}
in.close();
out.open(argv[2],ios::in | ios::nocreate);
if (out.fail())
{ rename(argv[1],argv[2]); }
else
cout<<“\nDuplicate file name or file is in use.”;
return 0;
}
Explanation: In the above program, the main() receives two file names. The existence of the
file can be checked by opening it in the read mode. If the file does not exist, the program is termi-
nated. On the other hand, if the second file exists, the renaming operation cannot be performed. ...