Write a function int Move(const char* szDest, const char* szSrc) that moves the file existing at szSrc to szDest and returns 1 if successful, 0 otherwise
File handling in c++ coding help?
This is just a preliminary function which should help you get started. It is definitely not as flexible as mv, and calls remove() from the cstdio library. Rewrite as necessary.
int Move(const char* szDest, const char* szSrc)
{
ifstream infile;
ofstream outfile;
char c;
infile.open("oldfile.txt", fstream::in);
outfile.open("newfile.txt", fstream::out |fstream::trunc);
if (infile.good()) {while (infile.good())
{c=infile.get();
outfile.put(c);}
infile.close();
outfile.close();
remove("oldfile.txt");
}
else return 0;
return 1;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment