简体   繁体   English

C ++缩短wchar_t数组

[英]C++ Shorten wchar_t array

I need to shorten wchar_t array. 我需要缩短wchar_t数组。 Example: 例:

wchar_t* email = L"name@domain.com";
/ * Somehow leave in email just "name" * /

My idea to do that 我的想法是

wchar_t Domain = L"@domain.com";
if(!(pos = wcsstr(email, Domain)))
    return 0;

wcsncpy (pos,L"",1);

wcsstr returns address to "@domain.com"(0x000001 - email begins, 0x000005 @domain.com begins ) but there wont be any memory leaks or garbage? wcsstr返回地址到“ @ domain.com”(0x000001-电子邮件开始,0x000005 @ domain.com开始),但是不会有任何内存泄漏或垃圾?

No, that won't create any memory leaks because you aren't allocating any memory, or modifying your original email pointer. 不,这不会造成任何内存泄漏,因为您没有分配任何内存或修改原始email指针。

An easier and more efficient syntax, though, would be *pos = '\\0'; 不过,更简单,更有效的语法是*pos = '\\0';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM