wcsrchr

本文介绍宽字符串函数wcsrchr的使用方法,该函数用于查找宽字符在字符串中最后一次出现的位置。提供了函数原型、参数说明及返回值详情,并通过一个VS2013示例展示了如何使用此函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

const wchar_t* wcsrchr (const wchar_t* ws, wchar_t wc);

         wchar_t* wcsrchr (      wchar_t* ws, wchar_t wc);

查询字符在宽字符串中最后的位置。

结束符null被认为是字符串的一部分。因此,它也会被包括进来被查询。

它与strrchr(<cstring>)对宽字符的处理相等。

参数:

ws

C 宽字符串

wc

需要查询的C字符串


返回值

返回一个指针,该指针指向wc字符在ws字符串中出现的最后位置处

如果wc没有找到,函数返回null指针


可移植性

C语言中,函数只声明以下方式:

wchar_t *wcsrchr(const wchar_t *, wchar_t);


实例vs2013:

/* wcsrchr example */
#include "stdafx.h"
#include <wchar.h>
#pragma warning(disable:4996)
int main ()
{
  wchar_t wcs[] = L"This is a sample wide string";
  wchar_t * pwc;
  pwc = wcsrchr (wcs,L's');
  wprintf (L"Last occurence of L's' found at %d \n",pwc-wcs+1);
  return 0;
}


输出:


最后一次出现的位置23。

如下报错,如何解决 In file included from src/SM2.cc:1: In file included from src/SM2.h:3: In file included from incs/gmp.h:34: In file included from /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/iosfwd:99: In file included from /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/__mbstate_t.h:29: /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:141:77: error: use of undeclared identifier 'wcschr' wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcschr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:148:87: error: use of undeclared identifier 'wcspbrk' wchar_t* __libcpp_wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcspbrk(__s1, __s2);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:155:78: error: use of undeclared identifier 'wcsrchr'; did you mean 'wcschr'? wchar_t* __libcpp_wcsrchr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcsrchr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:143:16: note: 'wcschr' declared here const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:162:86: error: use of undeclared identifier 'wcsstr'; did you mean 'wcschr'? wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:145:16: note: 'wcschr' declared here wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:162:86: error: no matching function for call to 'wcschr' wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:145:16: note: candidate disabled: <no message provided> wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);} ^ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:162:93: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'const wchar_t *' wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);} ^~~~ /home/lzw/ohos-sdk/linux/native/llvm/include/c++/v1/wchar.h:145:38: note: passing argument to parameter '__s' here wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);}
最新发布
06-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值