You can easily compare char array in c++ using following program. I have written this code for you. In the following code I have use iostream.h class to include all input and output methods. In the following code I have use std::string function to compare char array.
Code:
#include <iostream.h>
#include <string>
int main()
{
char nsw1 [10] = "Welcome to this world";
char nsw2 [10] = "Welcome to this world";
if (strcmp(nsw1,nsw2) == 0) {
cout << "match\n";
}
else {
cout << "doesn't match\n";
}
std::string ans1 = "Welcome to this world";
std::string ans2 = "Welcome to this world";
if (ans1 == ans2) {
cout << "matches\n";
}
else {
cout << "doesn't match\n";
}
return 0;
}
Bookmarks