gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
how to comapre two string equal in c++
- User
how to comapre two string equal in c++
- Assistant
In C++, you can compare two strings for equality using the
==operator if you're using thestd::stringclass from the Standard Library. Here’s a simple example:#include <iostream> #include <string> int main() { std::string str1 = "Hello, World!"; std::string str2 = "Hello, World!"; std::string str3 = "Goodbye, World!"; // Comparing strings using the == operator if (str1 == str2) { std::cout << "str1 is equal to str2" << std::endl; } else { std::cout << "str1 is not equal to str2" << std::endl; } if (str1 == str3) { std::cout << "str1 is equal to str3" << std::endl; } else { std::cout << "str1 is not equal to str3" << std::endl; } return 0; }