Determine if a string has all the same characters: Difference between revisions

m
C++ - 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 <stringstring_view>
 
void all_characters_are_the_same(const std::string&string_view str) {
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
<< "' (hex " << std::hex << static_cast<unsigned int>(str[i])
<< ") at position " << std::dec << i + 1
<< " is not the same as '" << ch << "'.\n\n";
return;
}
1,777

edits