file-reverse.cpp

来自「ace开发环境 用来开发网络程序 其运用了设计模式、多平台、C++等多种知识」· C++ 代码 · 共 60 行

CPP
60
字号
// $Id: file-reverse.cpp 75115 2006-10-27 23:51:23Z ossama $// Print a file in reverse by using the ACE memory mapped file// wrapper.  It is SO easy to do compared with alternatives!#include "ace/OS_main.h"#include "ace/Mem_Map.h"#include "ace/Log_Msg.h"ACE_RCSID(file_reverse, file_reverse, "$Id: file-reverse.cpp 75115 2006-10-27 23:51:23Z ossama $")static voidputline (const char *s){  while (putchar (*s++) != '\n')    continue;}static voidprint_array_in_reverse (char *array,                        int size){  if (size <= 0)    return;  size--;  if (array[size] == '\0')    array[size] = '\n';  while (--size >= 0)    if (array[size] == '\n')      putline (array + size + 1);  putline (array);}intACE_TMAIN (int argc, ACE_TCHAR **argv){  ACE_LOG_MSG->open (argv[0]);  if (argc != 2)    ACE_ERROR_RETURN ((LM_ERROR,                       "usage: %n file\n"),                      -1);  ACE_Mem_Map mmap;  if (mmap.map (argv[1], static_cast<size_t> (-1), O_RDWR) == -1)    ACE_ERROR_RETURN ((LM_ERROR,                       "%n: %p\n",                       "mmap"),                      -1);  print_array_in_reverse ((char *) mmap.addr (),                          mmap.size ());  return 0;}

⌨️ 快捷键说明

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