比字符串指针退后一个字符。
重要
_mbsdec
和 _mbsdec_l
无法用于在 Windows 运行时中执行的应用程序。 有关详细信息,请参阅通用 Windows 平台应用中不支持的 CRT 函数。
语法
unsigned char *_strdec(
const unsigned char *start,
const unsigned char *current
);
unsigned wchar_t *_wcsdec(
const unsigned wchar_t *start,
const unsigned wchar_t *current
);
unsigned char *_mbsdec(
const unsigned char *start,
const unsigned char *current
);
unsigned char *_mbsdec_l(
const unsigned char *start,
const unsigned char *current,
_locale_t locale
);
参数
start
指向源字符串中任意字符(或 _mbsdec
和 _mbsdec_l
的任意多字节字符的第一个字节)的指针;在源字符串中,start
必须位于 current
之前。
current
指向源字符串中任意字符(或 _mbsdec
和 _mbsdec_l
的任意多字节字符的第一个字节)的指针;在源字符串中,current
必须位于 start
之后。
locale
要使用的区域设置。
返回值
_mbsdec
、_mbsdec_l
、_strdec
和 _wcsdec
均将返回一个指向紧接在 current
之前的字符的指针;如果 start
的值大于或等于 current
的值,则 _mbsdec
将返回 NULL
。 _tcsdec
映射到这些函数其中之一,其返回值取决于映射。
备注
_mbsdec
和 _mbsdec_l
函数返回指向紧接在 current
(位于包含 start
的字符串中)之前的多字节字符的第一个字节的指针。
输出值受区域设置的 LC_CTYPE
类别设置的影响。 有关详细信息,请参阅 setlocale
、 _wsetlocale
。 _mbsdec
根据当前正在使用的区域设置识别多字节字符序列;_mbsdec_l
是相同的,只不过它使用传递的区域设置参数。 有关详细信息,请参阅 Locale。
如果 start
或 current
为 NULL
,则将调用无效参数处理程序,如参数验证中所述。 如果允许执行继续,则此函数将返回 EINVAL
并将 errno
设置为 EINVAL
。
重要
这些函数可能容易受到的缓冲区溢出的威胁。 缓冲区溢出可以用于系统攻击,因为它们可能使权限的提升不能确保。 有关详细信息,请参阅避免缓冲区溢出。
默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态。
一般文本例程映射
Tchar.h 例程 | _UNICODE 和 _MBCS 未定义 |
_MBCS 已定义 |
_UNICODE 已定义 |
---|---|---|---|
_tcsdec |
_strdec |
_mbsdec |
_wcsdec |
_strdec
和 _wcsdec
是 _mbsdec
和 _mbsdec_l
的单字节字符和宽字符版本。 仅为此映射提供 _strdec
和 _wcsdec
,否则不应该使用它们。
要求
例程 | 必需的标头 | 可选标头 |
---|---|---|
_mbsdec |
<mbstring.h> | <mbctype.h> |
_mbsdec_l |
<mbstring.h> | <mbctype.h> |
_strdec |
<tchar.h> | |
_wcsdec |
<tchar.h> |
有关兼容性的详细信息,请参阅 兼容性。
示例
以下示例显示了 _tcsdec
的用法。
// crt_tcsdec.cpp
// Compile by using: cl /EHsc crt_tcsdec.cpp
#include <iostream>
#include <tchar.h>
using namespace std;
int main()
{
const TCHAR *str = _T("12345");
cout << "str: " << str << endl;
const TCHAR *str2;
str2 = str + 2;
cout << "str2: " << str2 << endl;
TCHAR *answer;
answer = _tcsdec( str, str2 );
cout << "answer: " << answer << endl;
return (0);
}
以下示例显示了 _mbsdec
的用法。
// crt_mbsdec.cpp
// Compile by using: cl /EHsc crt_mbsdec.c
#include <iostream>
#include <mbstring.h>
using namespace std;
int main()
{
char *str = "12345";
cout << "str: " << str << endl;
char *str2;
str2 = str + 2;
cout << "str2: " << str2 << endl;
unsigned char *answer;
answer = _mbsdec( reinterpret_cast<unsigned char *>( str ), reinterpret_cast<unsigned char *>( str2 ));
cout << "answer: " << answer << endl;
return (0);
}