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

📄 removeduplicates.cpp

📁 Think in C++ 第二版源码
💻 CPP
字号:
//: C26:RemoveDuplicates.cpp

// From Thinking in C++, 2nd Edition

// Available at http://www.BruceEckel.com

// (c) Bruce Eckel 1999

// Copyright notice in Copyright.txt

// Remove duplicate names from a mailing list

#include "readLower.h"

#include "../require.h"

#include <vector>

#include <algorithm>

using namespace std;



int main(int argc, char* argv[]) {

  requireArgs(argc, 2);

  vector<string> names;

  readLower(argv[1], names); 

  long before = names.size();

  // You must sort first for unique() to work:

  sort(names.begin(), names.end()); 

  // Remove adjacent duplicates:

  unique(names.begin(), names.end());

  long removed = before - names.size();

  ofstream out(argv[2]);

  assure(out, argv[2]);

  copy(names.begin(), names.end(),

       ostream_iterator<string>(out,"\n"));

  cout << removed << " names removed" << endl;

} ///:~

⌨️ 快捷键说明

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