#include <iostream>
#include <string>
std::string::size_type find_char(const std::string &s, char c, std::string::size_type &occurs)
{
auto ret = s.size();
occurs = 0;
for (decltype(ret) i = 0; i != s.size(); ++i)
{
if (s[i] == c)
{
if (ret == s.size())
ret = i;
++occurs;
}
}
return ret;
}
int main()
{
int ctr = 0;
const std::string s = "clock";
auto index = find_char(s, 'c', ctr);
std::cout << ctr;
}
G:\DCSTemp\String Size Type\main.cpp||In function 'int main()':|
G:\DCSTemp\String Size Type\main.cpp|24|error: invalid initialization of reference of type 'std::basic_string<char>::size_type& {aka unsigned int&}' from expression of type 'int'|
G:\DCSTemp\String Size Type\main.cpp|4|error: in passing argument 3 of 'std::basic_string<char>::size_type find_char(const string&, char, std::basic_string<char>::size_type&)'|
G:\DCSTemp\String Size Type\main.cpp|24|error: unable to deduce 'auto' from '<expression error>'|