Home > Back-end >  C, remove and rename function failure
C, remove and rename function failure

Time:09-20

Fstream file;
Ofstream outfile;
Char \ [100].
Int choice, I;
Cout & lt; <"1. Modify the name" & lt; <"2. Modify the gender" & lt; <"3. Date of birth & lt;" <"4. Modify the height & lt;" <"5. Modify the weight & lt;" <"6. Change the password" & lt; <7. Return to the menu "";
Cin & gt;> Choice;
The switch (choice) {
Case 1:
Char newname [10].
File. The open (name);
if (! The file) {
Cerr & lt; <"The open error!" ;
The exit (1);
} else {
Outfile. Open (" temp. Dat ", the ios: : out);
if (! Outfile) {
Cerr & lt; <"The open error!" ;
The exit (1);
} else {
For (I=0; I & lt; 2; I++) {
File. Getline (temp, 100);
Outfile & lt; }
Cout & lt; <"Please input your name:";
Cin & gt;> Newname.
Outfile & lt; <"Name:" & lt; File. Getline (temp, 100);
while (! File. The eof ()) {
File. Getline (temp, 100);
Outfile & lt; }
File. The close ();
Outfile. Close ();
Remove (name);
if (! Rename (temp. "dat", newname)) {
Cout & lt; & lt;" Modify success!" system("pause");
system("cls");
The menu ();
} else {
Cout & lt; <"Modified failure!" ;
}
}
}
break;
Case 2:
File. The open (name);
if (! The file) {
Cerr & lt; <"The open error!" ;
The exit (1);
} else {
Outfile. Open (" temp. Dat ", the ios: : out);
if (! Outfile) {
Cerr & lt; <"The open error!" ;
The exit (1);
} else {
For (I=0; I & lt; 3; I++) {
File. Getline (temp, 100);
Outfile & lt; }
Cout & lt; <"Please enter the gender:";
Cin & gt;> Sex;
Outfile & lt; <"Gender:" & lt; File. Getline (temp, 100);
while (! File. The eof ()) {
File. Getline (temp, 100);
Outfile & lt; }
File. The close ();
Outfile. Close ();
Remove (name);
if (! Rename (temp. "dat", name)) {
Cout & lt; & lt;" Modify success!" system("pause");
system("cls");
The menu ();
} else {
Cout & lt; <"Modified failure!" ;
Cout & lt; }
}
}
break;

The above two case is part of the code, case1 remove and rename can run, case2 fail, errno values is 17.
Also happened before, and later found to be forgot to close the flow, as a result, this time again... The inside of the name is the name of the prior input, the file is named after the name of, and application in the same directory,