比较巧的编程小乐趣

  • 处理字符串中字符的标准方式

    while(*str)
    {
    statements
    str++;
    }
  • 创建并填充字符串

    char * pstr = new char[n + 1];
    pstr = '\0';
    while(n-- > 0)
    pstr[n] = c
  • PI的表示:

C和C++中并没有提供Pi的数学常量表示,但是我们可以使用数学库的三角函数来表示。

#include <math.h>

#define PI (4 * atan(1))
posted @ 2014-01-17 22:07  而远之  阅读(129)  评论(0编辑  收藏  举报