hello dear friends
I have written a simple file merger and the code has been shown as bellow but I get an error that I do not how to solve it please guide me .

Attachments
#define _AFXDLL

#include <fstream>
#include <string>
#include <Cstringt.h>
#include <iostream>
#include <direct.h>
#include <afxv_w32.h>




using namespace std;

int main()
{
	string line1, line2 ; 
	string end_str ;
	CFileFind  finder;
	bool finding = finder.FindFile ();
	bool firstFile=1;
	bool condition;
//-------------------------------------------------------------	
	end_str = "<ENDFILE;" ;
	condition= 0;
	while (finding)
    {
	    finding = finder.FindNextFile();
		Cstring title = finder.GetFileName();
		ifstream fin (title);
		if(!fin) 
		{
			cout<< "cannot open input file \n";
			return 1;
		}	
		ofstream fout ("merge.cf"); 
		if (!fout) 
		{	
			cout<< "cannot open output file .\n";
			return 1;
		}
//..............................................................
		if(firstFile)
		{
			while (!fin.eof())
			{
				getline (fin,line1);
				getline (fin,line2);
				if (end_str==line2)
					condition=1;
				else 
					condition=0;
				if(!condition)
					fout<<line1<<'\n';
				else
					fout<<line1;
			}
			firstFile=0;
		}
		else 
		{
			getline (fin,line1);
			fout<<'\n';
			while (!fin.eof())
			{
				getline (fin,line1);
				fout<<line1<<'\n';
			}
		}
		fout.close();
	}
	finder.Close ();
	return 0;
}

Code this small can easily be embedded into your post, so in future, do it :icon_wink:

#define _AFXDLL

#include <fstream>
#include <string>
#include <Cstringt.h>
#include <iostream>
#include <direct.h>
#include <afxv_w32.h>

using namespace std;

int main()
{
	string line1, line2 ; 
	string end_str ;
	CFileFind  finder;
	bool finding = finder.FindFile ();
	bool firstFile=1;
	bool condition;
//-------------------------------------------------------------	
	end_str = "<ENDFILE;" ;
	condition= 0;
	while (finding)
    {
	    finding = finder.FindNextFile();
		Cstring title = finder.GetFileName();
		ifstream fin (title);
		if(!fin) 
		{
			cout<< "cannot open input file \n";
			return 1;
		}	
		ofstream fout ("merge.cf"); 
		if (!fout) 
		{	
			cout<< "cannot open output file .\n";
			return 1;
		}
//..............................................................
		if(firstFile)
		{
			while (!fin.eof())
			{
				getline (fin,line1);
				getline (fin,line2);
				if (end_str==line2)
					condition=1;
				else 
					condition=0;
				if(!condition)
					fout<<line1<<'\n';
				else
					fout<<line1;
			}
			firstFile=0;
		}
		else 
		{
			getline (fin,line1);
			fout<<'\n';
			while (!fin.eof())
			{
				getline (fin,line1);
				fout<<line1<<'\n';
			}
		}
		fout.close();
	}
	finder.Close ();
	return 0;
}
This article has been dead for over six months. Start a new discussion instead.