1

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
  • 115,525
  • 42
  • 225
  • 281
kiriloff
  • 24,401
  • 34
  • 141
  • 212

2 Answers2

11

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
  • 115,525
  • 42
  • 225
  • 281
Aleksey Bakin
  • 1,466
  • 12
  • 26
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,693
  • 1
  • 19
  • 31