本文整理汇总了C++中AnyString::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ AnyString::begin方法的具体用法?C++ AnyString::begin怎么用?C++ AnyString::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyString
的用法示例。
在下文中一共展示了AnyString::begin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
int Luhn::Mod10(const AnyString& s)
{
// The string must have at least one char
if (s.size() > 1)
{
// The algorithm :
// 1 - Counting from the check digit, which is the rightmost, and moving
// left, double the value of every second digit.
// 2 - Sum the digits of the products together with the undoubled digits
// from the original number.
// 3 - If the total ends in 0 (put another way, if the total modulo 10 is
// congruent to 0), then the number is valid according to the Luhn formula
//
static const int prefetch[] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9};
int sum = 0;
bool alternate = true;
const AnyString::iterator end = s.end();
// For each char
for (AnyString::iterator i = s.begin(); end != i; ++i)
{
// Each char in the string must be a digit
if (!String::IsDigit(i.value()))
return false;
// The `real` digit
int n = i.value() - '0';
// Computing the sum
sum += (alternate = !alternate) ? prefetch[n] : n;
}
return sum % 10;
}
return -1;
}