stshtst4.cpp

来自「Thinking in C++ 2nd edition source code 」· C++ 代码 · 共 42 行

CPP
42
字号
//: C07:Stshtst4.cpp
// From Thinking in C++, 2nd Edition
// at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
//{L} Stash4
// Function overloading
#include <cstdio>
#include "../require.h"
#include "Stash4.h"
using namespace std;
#define BUFSIZE 80

int main() {
  int i;
  FILE* file;
  char buf[BUFSIZE];
  char* cp;
  // ....
  Stash intStash(sizeof(int));
  for(i = 0; i < 100; i++)
    intStash.add(&i);
  file = fopen("STSHTST4.CPP", "r");
  require(file);
  // Holds 80-character strings:
  Stash stringStash(sizeof(char) * BUFSIZE);
  while(fgets(buf, BUFSIZE, file))
    stringStash.add(buf);
  fclose(file);

  for(i = 0; i < intStash.count(); i++)
    printf("intStash.fetch(%d) = %d\n", i,
           *(int*)intStash.fetch(i));

  i = 0;
  while(
    (cp = (char*)stringStash.fetch(i++)) != 0)
    printf("stringStash.fetch(%d) = %s",
           i - 1, cp);
  putchar('\n');
} ///:~

⌨️ 快捷键说明

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