2

I am reading Googletest doc, and I am learning that there is one syntax for comparing string, and another for comparing C string. I dont see what is referred to as C string and as string. How are these different?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
kiriloff
  • 25,609
  • 37
  • 148
  • 229

2 Answers2

12

If you try to use ASSERT_EQ to C-Strings, you only compare two pointers, but not really null-terminated C-Strings. For that exists ASSERT_STREQ syntax.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Aleksey Bakin
  • 1,506
  • 13
  • 27
2

std::string is often called C++ string. Using strings like

 const char *text = "text";

is called CStrings.

much more information can be found here:

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

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

Community
  • 1
  • 1
CyberGuy
  • 2,783
  • 1
  • 21
  • 31