Determine if a string has all the same characters: Difference between revisions
Determine if a string has all the same characters (view source)
Revision as of 09:59, 5 April 2024
, 1 month agoC++ - replaced string by string_view
imported>Fth No edit summary |
m (C++ - replaced string by string_view) |
||
Line 912:
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <iostream>
#include <
void all_characters_are_the_same(
size_t len = str.length();
std::cout << "input: \"" << str << "\", length: " << len << '\n';
Line 922:
if (str[i] != ch) {
std::cout << "Not all characters are the same.\n";
std::cout << "Character '" << str[i] << "' (hex " << std::hex
<< ") at position " << std::dec << i + 1
<< " is not the same as '" << ch << "'.\n\n";
return;
}
|