我的代码没有编译,任何人都可以帮我弄清楚我做错了什么?

时间:2014-03-14 21:08:36

标签: c++

到目前为止,这是我为我的程序提出的,但我无法弄清楚为什么它不能正确编译,我遇到了很多错误。有人有什么建议吗?该程序需要从两个不同的文件合并男性和女性客户端并输出到另一个文件。谢谢!

#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{

     ifstream inFile1;
     ifstream inFile2;
     ofstream outFile1;
     int mClientNumber, fClientNumber;
     string mClientName, fClientName;
     bool atLeastOneFileNotAtEnd = true;
     bool inFile1Written = false;
     bool inFile2Written = false;
 cout << "File merge processing starting" ;
 inFile1.open("MaleClients.rtf");
 inFile2.open("FemaleClients.rtf");
 outFile1.open("MergedClients.rtf");
 inFile1 >> mClientNumber;
 inFile1 >> mClientName;
 inFile2 >> fClientNumber;
 inFile2 >> fClientName;
 while ( atLeastOneFileNotAtEnd == true )
 {
   if (inFile1 == EOF)
   {
     if (inFile2Written == false)
     {
       outFile1 << fClientNumber << endl;
       outFile1 << fClientName << endl;
       inFile2Written = true;
     }
   else if (inFile2 == EOF)
     if (inFile1Written == false);
     {
       outFile1 << mClientNumber << endl;
       outFile1 << mClientName << endl;
       inFile1Written = true;
     }
   else if (mClientNumber < fClientNumber)
     outFile1 << mClientNumber << endl;
     outFile1 << mClientName << endl;
     inFile1Written = true;
   else
     outFile1 << fClientNumber << endl;
     outFile1 << fClientName << endl;
     inFile2Written = true;
   }


   if ((inFile1 ! EOF) && (inFile1Written == true))
   {
     inFile1 >> mClientNumber;
     inFile1 >> mClientName;
     inFile1Written = false;
   }
   if ((inFile2 ! EOF) && (inFile2Written == true))
   {

     inFile2 >> fClientNumber;
     inFile2 >> fClientName;
     inFile2Written = false;
   }
   if ((inFile == EOF) && (inFile2 == EOF))
   {
     atLeastOneFileNotAtEnd = false;
   }
 }
 inFile1.close();
 inFile2.close();
 outFile1.close();
 cout << "Merging Complete"

  system("pause");
  return 0;

}

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

您正在使用C中的EOF宏。无需执行此操作。坚持使用C ++并使用ifstream.eof(),并删除cstdlib include。