#include <iostream>
using namespace std;
// Ищет символ согласно условия
template<class _Ty>
int find_last_chr(const _Ty* const str,_Ty what)
{
const _Ty* cur=str;
int result=-1;
while(*cur)
{
if(*cur==what)
{
result=cur-str;
}
++cur;
}
return result;
}
int main()
{
locale::global(locale(""));
char* cstr="This is a string";
wchar_t* wstr=L"This is a wide-char string";
// Пробуем для строк состоящих из char символов
cout<<"В строке ""<<cstr<<"""<<endl;
cout<<"i:"<<find_last_chr(cstr,'i')<<endl;
cout<<"m:"<<find_last_chr(cstr,'m')<<endl;
// Пробуем для строк состоящих из wchar_t символов
wcout<<L"В строке ""<<wstr<<L"""<<endl;
wcout<<L"g:"<<find_last_chr(wstr,L'g')<<endl;
wcout<<L"z:"<<find_last_chr(wstr,L'z')<<endl;
system("PAUSE");
return 0;
}
В строке "This is a string"
i:13
m:-1
В строке "This is a wide-char string"
g:25
z:-1
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.