Home > Back-end >  Why I will write to the file before, the content of the right to change the file, the output is the
Why I will write to the file before, the content of the right to change the file, the output is the

Time:09-25


System (" CLS ");
COURSE * pt=new COURSE;
Char no [20].
Ifstream inFile (" fCourse. TXT ", the ios: : binary | ios: : in);
if(! InFile)
{
Cout<" File open exception!" }
Cout<" If input change student student id: "& lt; Cin> No;

if(! InFile)
Cout<" File open failed!" The else
{

while(! InFile. Eof ())
{
InFile. Read (reinterpret_cast & lt; Char * & gt; (pt), sizeof (COURSE));
//inFile> STU.
If (STRCMP (pt - & gt; Cour_num, no)==0)
{
//strncpy (sTemp - & gt; CName, STU, 7);
//inFile> STemp - & gt; CNo> STemp - & gt; CName> STemp - & gt; CSex> STemp - & gt; NYear> STemp - & gt; NMonth> STemp - & gt; NDay> STemp - & gt; CMajor;

If (inFile. Gcount ()!=0)
Cout<" T \ \ t \ t * * * * * * this course basic information "& lt; Cout<" \ t course number t \ \ t name \ t course credits \ t nature "& lt; Cout<" \ t "& lt; }

}
}
COURSE * p=new COURSE + 1;
InFile. Close ();
Cout<" Whether to modify course information? (1, 0 no) "& lt; int i;
Cin> i;
If (I==0)
{
System (" pause ");
The menu ();
}
The else
{
Ofstream outFile (" fCourse. TXT ", the ios: : out);
OutFile. Seekp (sizeof (p), the ios: : cur);
Cout<" Please input the modified information: "& lt; //cout<" : \ t course code name \ \ t t \ \ t t credit course nature "& lt; Cout<" Courses: ";
Cin> P - & gt; Cour_num;
Cout<" Course name: ";
Cin> P - & gt; Cour_name;
Cout<" Course credits: ";
Cin> P - & gt; Cour_score;
Cout<" Course nature: ";
Cin> P - & gt; Cour_Feature;
OutFile. Write (reinterpret_cast & lt; Char * & gt; (p), sizeof (COURSE));
OutFile. Close ();

CodePudding user response:

OutFile. Seekp (sizeof (p), the ios: : cur);
Ios: : cur have changed the current position?
  • Related