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

📄 binder4.cpp

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

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

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

// (c) Bruce Eckel 1999

// Copyright notice in Copyright.txt

// The bound argument does not have 

// to be a compile-time constant

#include "copy_if.h"

#include "PrintSequence.h"

#include "../require.h"

#include <iostream>

#include <algorithm>

#include <functional>

#include <cstdlib>

using namespace std;



int boundedRand() { return rand() % 100; }



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

  requireArgs(argc, 1, "usage: Binder4 int");

  const int sz = 20;

  int a[20], b[20] = {0};

  generate(a, a + sz, boundedRand);

  int* end = copy_if(a, a + sz, b, 

    bind2nd(greater<int>(), atoi(argv[1])));

  // Sort for easier viewing:

  sort(a, a + sz);

  sort(b, end);

  print(a, a + sz, "array a", " ");

  print(b, end, "values greater than yours"," ");

} ///:~

⌨️ 快捷键说明

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