我爱Aspx >> VC.Net >> <b>正确地调用字符串相关的函数(第一部分)</b>即便在常规的程序开发过程中,程序员也常常会碰到调用字符串函数方面的困难。注意,这里的字符串函数是指有关字符指针操作相关的函数。例如,我们现有这么一个函数:reverse_string:
template< class CharType>
void reverse_string( const CharType * strDest)
{
int nLength = /* what should we call here? */;
int idxFirst = 0;
int idxLast = nLength - 1;
while ( idxFirst < idxLast)
{
std::swap( strDest[ idxFirst], strDest[ idxLast];
++ idxFirst;
-- idxLast;
)
}
在/* what should we call here? */位置,我们使用strlen来调用const char *字符串,使用wcslen来调用const wchar_t *字符串。
解决方法是建立一个t_strlen函数,如下所示:
template< class CharType>
int t_strlen( const CharType * str)
{
return strlen( str);
}
int t_strlen( const wchar_t * str)
{
return wcslen( str);
}
【我对这篇文章有话说?】
<b>从赋值运算符的默认实现..[05-21]
<b>从赋值运算符的默认实现..[05-21]
<b>Visual C++编程中的文件..[05-21]
<b>Visual C++中的ODBC编程..[05-21]
<b>常见Visual C++开发使用..[05-21]
<b>常见Visual C++开发使用..[05-21]
<b>应用程序中超文本浏览功..[05-21]
<b>Visual C++窗体设计技巧..[05-21]
<b>C++编程技巧</b>[05-21]
<b>Visual C++实现Flash动..[05-21]