Home > Back-end >  Ask: why the output from the file content to the screen, the one and only the first word garbled? Bu
Ask: why the output from the file content to the screen, the one and only the first word garbled? Bu

Time:01-20



 void Reserve: : Add ()//reservation 
{

Ofstream ofs (" d: \ \ hotel system. TXT ", the ios: : out | ios: : app);
If (ofs. Is_open ())
{
Reserve e;
Cout & lt; <"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" & lt; Cout & lt; <"Please enter the reservation number:" & lt; Int addnum=0;
Cin & gt;> Addnum;


Cout & lt; <"Please input the name of the inhabitants, id number, check-in date, ordered room:" & lt; For (int j=0; J & lt; Addnum; J++)
{
Cin & gt;> e;

Ofs & lt; }
Ofs. Close ();
}

Void Reserve: : show ()//check reservation record
{
Fstream fd (" d: \ \ Hotel system. TXT ", the ios: : in);
Int ch;//define a character
Ch=fd. The get ();//a character read from the file
If (EOF) ch==//if didn't read a single character, said the file is empty
{
Cout & lt; <"The blank file, can't read!" }
The else
{
Cout & lt; <"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" & lt; Cout & lt; Int n=0; String STR.
Reserve * e=new Reserve [50];

While (getline (fd, STR))
{

Cout & lt; <"";
Cout}

Fd. The close ();
}
}


Above is for input and output of the code, the folder class set about to pay, please comment, thank you!!!!!

CodePudding user response:

File may not be a blank, or have BOM,
To create a completely blank 0 bytes of file try,
  • Related