比较两文件中相同的字符,并存入第三个文件

#include "stdafx.h"
#include 
#include 
#include 
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
	ofstream outfile3;
	ifstream readfile1;
	ifstream readfile2;

	outfile3.open("text_three.txt");
	readfile1.open("text_one.txt");
	readfile2.open("text_two.txt");

	char buffer1[50]; //定义输出输入缓冲区
	char buffer2[50];

	if (readfile1.is_open())
		readfile1.getline(buffer1, 50); //读取一行
	if (readfile2.is_open())
		readfile2.getline(buffer2, 50);

	for (int i = 0; i < strlen(buffer1); i++)
	{
		for (int j = 0; j < strlen(buffer2); j++)
		{
			if ((buffer1[i] == buffer2[i]))
			{
				outfile3 << buffer1[i]; //输出文件并且输出在屏幕
				cout << buffer1[i] << ' ';
			}
			break;
		}
	}
	system("pause");
	return 0;
}

 

你可能感兴趣的:(vc++/c++/mfc学习)