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

📄 tstest.cpp

📁 Thinking in C++ 2nd edition source code which are all the cores of the book Thinking in C++ second e
💻 CPP
字号:
//: C16:Tstest.cpp
// From Thinking in C++, 2nd Edition
// at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Test TStash
#include <fstream>
#include <vector>
#include <string>
#include "../require.h"
#include "TStash.h"
using namespace std;
ofstream out("tstest.out");

class Int {
  int i;
public:
  Int(int I = 0) : i(I) {
    out << ">" << i << endl;
  }
  ~Int() { out << "~" << i << endl; }
  operator int() const { return i; }
  friend ostream&
    operator<<(ostream& os, const Int& x) {
      return os << x.i;
  }
};

int main() {
  TStash<Int> intStash; // Instantiate for int
  for(int i = 0; i < 30; i++)
    intStash.add(new Int(i));
  TStashIter<Int> Intit(intStash);
  Intit.forward(5);
  for(int j = 0; j < 20; j++, Intit++)
    Intit.remove(); // Default removal
  for(int k = 0; k < intStash.count(); k++)
    if(intStash[k]) // Remove() causes "holes"
      out << *intStash[k] << endl;

  ifstream file("tstest.cpp");
  assure(file, "tstest.cpp");
  // Instantiate for String:
  TStash<string> stringStash;
  string line;
  while(getline(file, line))
    stringStash.add(new string(line));
  for(int u = 0; u < stringStash.count(); u++)
    if(stringStash[u])
      out << *stringStash[u] << endl;
  TStashIter<string> it(stringStash);
  int j = 25;
  it.forward(j);
  while(it) {
    out << j++ << ": " << it->c_str() << endl;
    it++;
  }
} ///:~

⌨️ 快捷键说明

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