⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 combineline.cpp

📁 这是一些c++例程
💻 CPP
字号:
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <vector>

// 因为使用了STL库,所以使用std名字空间
using namespace std;

// 功能函数的提前声明
bool Index(string Substr,string Str);

// 主函数
void main()
{
	vector<string> str;				// 定义一个string的vector来存储所有出现过的行
	
	ifstream in("src.txt");		// 打开源文件 
	if(in.fail())
	{
		cout<<"Open File Failure!\n";
		in.close();
		exit(1);
	}

	ofstream out("dst.txt");		// 打开目标文件
	
	string line;
	while(getline(in,line))
	{       
		for(int j=0;j<str.size();j++)
		{
			if(Index(line,str[j]))	// 如果line是以前某行的一部分或全部
				break;
		}
		if(j==str.size())			// line是全新的
		{
			str.push_back(line);	// 将起加入到vector中
			out<<line<<endl;		// 输出到目标文件中
		}
	}
	// 关闭文件流
	in.close();
	out.close();
}

/* 函数功能:判断Substr是否在Str中,在则返回true,否则返回false. */
bool Index(string Substr,string Str)   			
{
	int SubLength=Substr.size();
	int StrLength=Str.size();
	for(int i=0;i<StrLength-SubLength+1;i++)
	{
		if(Substr==Str.substr(i,SubLength))
			return true;	
	}
	return false;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -