troubleshooting Question

Problem using file streams with file data with spaces

Avatar of nfcdrummer
nfcdrummerFlag for Australia asked on
C++
3 Comments1 Solution325 ViewsLast Modified:
Hi,

I'm working on a 'personal records' sort of program.  Anyway, the format for the files is as such:

Name
Address
Home Phone
Mobile Phone
Email Address
Date of Birth

for example:

John Doe
123 Liveshere street, Erewhon, 1234
(01) 234 567
(0141) 234 567
johndoe@nonexistant.net
3/3/1914

Now, after running through this code:

     int yay = false;
     int conf = Application->MessageBox("Are these details correct?",
                                                            "Confirm Details",
                                         MB_YESNO);
   if (conf == IDYES)
   {
          // Now the fun starts!  We now create the file if it does not
      // exist, and then add the new data to the end!
      ofstream outDF, outTF;
      ifstream inDF, inTF;
      string cTemp;


      inDF.open("data.dat");
      if (inDF)
      {
              outTF.open("data.tmp"); // opens the temp file
           while (!inDF.eof())
           {
              inDF >> cTemp;          // writes the data from the data file
            outTF << cTemp << endl;     // to the temp file
         }
         outTF.close();
         inDF.close();
      }

          outDF.open("data.dat");
      if (!outDF)     // if file cannot be created, gives an error.
      {
             Application -> MessageBox
                ("Error creating data file!", "Oh no!", MB_OK);
         yay = false;
      } else
      {
           inTF.open("data.tmp");
               if (inTF)
         {
              while(!inTF.eof())
              {
                   inTF >> cTemp;
               outDF << cTemp << endl;
              }
              // Close and delete the temp file...
              inTF.close();
              //DeleteFile("data.tmp");
         }

         // Convert the strings to chars and save to the file!
         outDF << edtName->Text.c_str() << endl;
         outDF << edtAddress->Text.c_str() << endl;
         outDF << edtHPhone->Text.c_str() << endl;
         outDF << edtMPhone->Text.c_str() << endl;
         outDF << edtEmail->Text.c_str() << endl;
         outDF << edtDOB->Text.c_str() << endl;

         // Close the data file...
         outDF.close();


         // And make it display the successful confirmation window!
               yay = true;
      }

        // Once all saving of data is complete, erase the data fields.
          edtName->Text = "";
        edtAddress->Text = "";
        edtHPhone->Text = "";
        edtMPhone->Text = "";
        edtEmail->Text = "";
        edtDOB->Text = "";
      if (yay)
      {
           Application -> MessageBox
              ("Data was saved successfully!","Hooray!", MB_OK);
      } else
      {
           Application -> MessageBox
              ("Data was NOT saved successfully!","Oh no!", MB_OK);
      }

          // Now close the window.
        frmStuff->Close();
   }
}


the data comes as such (not including the new data entered)

John
Doe
123
Liveshere
street,
Erewhon,
1234
(01)
234
567
(0141)
234
567
johndoe@nonexistant.net
3/3/1914
3/3/1914
3/3/1914


Anyway, I would *really* appreciate help.  All the code that I've used is in that block up there.  Thanks in advance!
ASKER CERTIFIED SOLUTION
JeromeCaQcMtl

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros