nesttest.cpp
来自「Thinking in C++ 2nd edition source code 」· C++ 代码 · 共 38 行
CPP
38 行
//: C04:NestTest.cpp
// From Thinking in C++, 2nd Edition
// at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
//{L} Nested
//{T} NestTest.cpp
// Test of nested linked list
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "../require.h"
#include "Nested.h"
using namespace std;
int main(int argc, char* argv[]) {
Stack textlines;
FILE* file;
char* s;
#define BUFSIZE 100
char buf[BUFSIZE];
requireArgs(argc, 2); // File name is argument
textlines.initialize();
file = fopen(argv[1], "r");
require(file != 0);
// Read file and store lines in the Stack:
while(fgets(buf, BUFSIZE, file)) {
char* string =(char*)malloc(strlen(buf)+1);
require(string != 0);
strcpy(string, buf);
textlines.push(string);
}
// Pop the lines from the Stack and print them:
while((s = (char*)textlines.pop()) != 0) {
printf("%s", s); free(s); }
textlines.cleanup();
} ///:~
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?