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

📄 tstacktest.cpp

📁 希望我提供的代码对大家有帮助
💻 CPP
字号:
//: C16:TStackTest.cpp

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

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

// (c) Bruce Eckel 1999

// Copyright notice in Copyright.txt

// Use template list & iterator

#include "TStack.h"

#include "../require.h"

#include <iostream>

#include <fstream>

#include <string>

using namespace std;



int main() {

  ifstream file("TStackTest.cpp");

  assure(file, "TStackTest.cpp");

  TStack<string> textlines;

  // Read file and store lines in the list:

  string line;

  while(getline(file, line))

    textlines.push(new string(line));

  int i = 0;

  // Use iterator to print lines from the list:

  TStackIterator<string> it(textlines);

  TStackIterator<string>* it2 = 0;

  while(it) {

    cout << *it.current() << endl;

    it++;

    if(++i == 10) // Remember 10th line

      it2 = new TStackIterator<string>(it);

  }

  cout << *(it2->current()) << endl;

  delete it2;

} ///:~

⌨️ 快捷键说明

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