【问题标题】:googletest doc C string and stringgoogletest doc C 字符串和字符串
【发布时间】:2015-12-04 14:53:02
【问题描述】:

我正在阅读Googletest doc,我了解到有一种用于比较字符串的语法,另一种用于比较 C 字符串。我没有看到所谓的 C 字符串和字符串。这些有何不同?

【问题讨论】:

    标签: c++ c string googletest


    【解决方案1】:

    如果您尝试将ASSERT_EQ 用于C-Strings,您只会比较两个指针,而不是真正以null 终止的C-Strings。为此存在ASSERT_STREQ 语法。

    【讨论】:

      【解决方案2】:

      std::string 通常称为C++ string。使用像

      这样的字符串
       const char *text = "text";
      

      被称为 CStrings。

      更多信息可以在这里找到:

      What is the difference between char * const and const char *?

      When to use const char * and when to use const char []

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-06-09
        • 2013-10-25
        • 2020-08-23
        • 2012-07-16
        • 1970-01-01
        • 2012-10-09
        • 2015-10-28
        相关资源
        最近更新 更多