Skip to content

Instantly share code, notes, and snippets.

@asa55
Created April 3, 2020 22:33
Show Gist options
  • Save asa55/0dcdd4714ac1daf3a7762605e765d000 to your computer and use it in GitHub Desktop.
Save asa55/0dcdd4714ac1daf3a7762605e765d000 to your computer and use it in GitHub Desktop.
// How do you print the first non-repeated character from a string?
#include <iostream>
#include <string>
std::string my_str = "aaaaaaabccccccc";
int main ()
{
int index;
for (index = 0; index < my_str.size() - 1; ++index)
if ( my_str[index] != my_str[index + 1] ) break;
std::cout << my_str[index + 1] << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment