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

📄 main.cpp

📁 一本语言类编程书籍
💻 CPP
字号:
// Exercise 18.2 Exercising the LinkedList template class
// This program reverses the text that is entered
#include "LinkedListT.h"
#include <string>
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::string;

int main() {
  string text;                             // Stores input prose or poem
  cout << "\nEnter a poem or prose over one or more lines."
       << "Terminate the input with #:\n";
  getline(cin, text, '#');

  LinkedList<string> words;                // List to store words

  // Extract words and store in the list
  string separators(" ,.\"?!;:");          // Separators between words
  int start = 0;                           // Start of a word
  int end = 0;                             // separator position after a word
  while(string::npos != (start = text.find_first_not_of(separators, start))) {
    end = text.find_first_of(separators, start+1);
    words.addTail(&text.substr(start,end-start));
    start = end;
  }

  // List the words in reverse order 5 to a line
  string* pStr = words.getTail();
  int count = 0;                           // Word counter
  while(pStr) {
    if(count++ % 5 == 0)
      cout << endl;
    cout << *pStr << ' ';
    pStr = words.getPrevious();
  }

  cout << endl;
  return 0;
}

⌨️ 快捷键说明

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