google风格C++代码规范(长期更新)最近更新:2020.6.5
发布日期:2021-05-28 16:53:13 浏览次数:33 分类:精选文章

本文共 714 字,大约阅读时间需要 2 分钟。

Google 风格代码规范(长期更新)

参数传递规则

  • 顺序:入参放在前,出参放在后。
  • 规范:入参需用 const 引用,出参用指针,禁止用非 const 引用代替指针。
  • 例子:

    int add(const int &num, int *result) {    *result = (*result) + num;    return 0;}

    不规范写法:

    int add(int num, int &result) {    result = result + num;    return 0;}

    Chrono 与 Ctime

    <chrono> 是非准确的 C++11 头文件,建议使用 <ctime>。参考资料:Chromium C++ 标准库

    为了使用 re2,可以采取以下方式:

  • 从GitHub下载 re2
  • 使用本地头文件的方式引用(双引号方式)
  • 例子:

    #include "re2/re2.h" // 通常需要搭配特定的 build услов Blob 及定义// 或采用库的方式(使用尖括号形式)

    建议的 for 循环写法:

    for (auto iter : NumVec) {    std::cout << iter;}或for (int i = 0; i < NumVec.size(); ++i) {    std::cout << NumVec[i];}

    建议的 if 语句写法:

    int a = 0;if (a == 1) {    std::cout << "a = 1" << std::endl;} else {    std::cout << "a = 0" << std::endl;}
    上一篇:带参Lambda表达式
    下一篇:idea/Clion/Pycharm的正则表达式搜索/模糊搜索/通配符搜索

    发表评论

    最新留言

    留言是一种美德,欢迎回访!
    [***.207.175.100]2025年04月17日 16时30分01秒