foreach - C++ for_each algo and string -


I am trying to loop through every letter of the string, for_each,

  Std :: unordered_map & lt; Std :: string, unsigned int & gt; Dico; Std :: for_each (str.begin (), str.end (), [& amp;] (std :: string l) {if (dico.count (l) == 0) {'anything is here}}  

However, I have received an error message:

  Error 2 error C2664: 'zero' anonymous-name space ':: & lt; lambda2 & Gt; :: Operator () (Std :: string) const ':' const char 'parameter 1 of' std :: string 'can not be changed  

I < Code> char l However, it can break the dico.count (l) instead, I for loop I use I have seen that solution worked, however, I wonder why for_each will not work here.

  Std :: unordered_map  dico; "[" a "] = 1; deco [" b "] = 1; [ C "] = 1; Std :: string str (" abcd "); Std :: for_each (str.begin (), str.end (), [& amp;] (four l) {std :: string s ( 1, L); // if is fixed (dico.count (s) == 0) {std :: cout & lt; & Lt; "1" & lt; & Lt; Std :: endl;}});  

This should work

The problem is that you do not start char using string You may need either another string (C ++ string) (C string) (C string).

In addition to this you can actually enter std :: unordered_map & lt; Char, unsigned int & gt;


Edit on the basis of Rob Kennedy's comment:

const char * cc = & amp; L

. Now the right CTO of std :: string is saying.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -