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

📄 string.cpp

📁 一个string类的处理数据重复以及输出每个数据
💻 CPP
字号:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
int main()
{
	ifstream in("stringin.txt");
	ofstream out("stringout.txt");
	string x;
	int i,temp;
	vector<string>data;
	while (in>>x) data.push_back(x);
	sort(data.begin(),data.end());
	temp=0;
	for (i=0;i<data.size()-1;i++)
	{
		if (data[i]==data[i+1]) temp++;
		else 
		{	
			out<<"单词 "<<data[i]<<"出现次数为:"<<temp+1<<"次"<<endl;
			temp=0;
		}
	}
	out<<"单词 "<<data[data.size()-1]<<"出现次数为:"<<temp+1<<"次"<<endl;
	return 1;
}

⌨️ 快捷键说明

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