@Lisik

Как сравнить 2 введенных слова?

Пробую через strcmp, но пока не получается.
string name1;
	while (getline(cin, name1)) {
                     ...
			continue;
		}
		break;
	}
...
string name2;
	while (getline(cin, name2)) {
		...
}
		else if (strcmp(name1, name2) == 1)
			cout << "..." << endl;
	}
  • Вопрос задан
  • 63 просмотра
Решения вопроса 1
jcmvbkbc
@jcmvbkbc
"I'm here to consult you" © Dogbert
if (strcmp(name1, name2) == 1)

man strcmp
The strcmp() and strncmp() functions return an integer less than,
       equal to, or greater than zero if s1 (or the first n bytes thereof)
       is found, respectively, to be less than, to match, or be greater than
       s2.

Для проверки на равенство должно быть
if (strcmp(name1.c_str(), name2.c_str()) == 0)
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
myjcom
@myjcom Куратор тега C++
Вы в std::string считываете.
name1.compare(name2); //strcmp()
https://ru.cppreference.com/w/cpp/string/basic_str...

name1 == name2; //operator==
https://ru.cppreference.com/w/cpp/string/basic_str...
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы