1

is there a c++ standard function to check the similarity between two strings parameters by returning for example the number of similar characters .

this
  • 5,229
  • 1
  • 22
  • 51
  • 4
    What do you mean by similar? – Baum mit Augen Jun 03 '14 at 23:25
  • 3
    what do you mean "number of similar characters"? – Matt Coubrough Jun 03 '14 at 23:25
  • 3
    Are you looking for something like Levenshtein Distance (http://en.wikipedia.org/wiki/Levenshtein_distance)? There's no standard function for this, but I'm sure you can find an implementation somewhere. – user2303197 Jun 03 '14 at 23:29
  • 2
    You probably are looking for [edit distance](http://en.wikipedia.org/wiki/Edit_distance), there are many definitions of edit distances, Levenshtein distance being one of the most common one, but the similarity between all of them is that none of them are available in the standard library. – Lie Ryan Jun 03 '14 at 23:31

2 Answers2

4

No, there is not. You can view all standard C++ functions at cppreference.com. There you will see that the basic_string type has nothing like that and the algorithms library has nothing like that, and there's pretty much no other place to put something like that, so, no.

jwodder
  • 54,758
  • 12
  • 108
  • 124
1

You can do this for each character of the String.

Extract from the link

#include <algorithm>

std::string s = "a_b_c";
size_t n = std::count(s.begin(), s.end(), '_');

There is no function to count similarities like you need.

Community
  • 1
  • 1
Orelsanpls
  • 22,456
  • 6
  • 42
  • 69