gpt4 book ai didi

c++ - LPWSTR 字符串到 bool?

转载 作者:太空宇宙 更新时间:2023-11-04 15:29:19 25 4
gpt4 key购买 nike

我有一个 LPWSTR 类型的变量,其中包含 "true""false"。有没有一种方法可以将其转换为具有 truefalse 的 bool 类型的变量?

理想情况下我想做这样的事情:

FooClas::MyMethod()
{
LPWSTR variableOne;
bool variableTwo;
MyMethodOne(&variableOne);

// At this point, variableOne can be either "true" or "false".
// Do something to check if "true", then variableTwo = true, otherwise variableTwo = false.
}

最佳答案

给定前提条件,即 variableOne 指向 "true""false",这是将其转换为 bool 值将是:

bool const variableTwo { *variableOne == L't' };

测试单个区分属性(例如第一个字符)就足够了。任何其他字符,甚至字符串的长度都同样足够。

关于c++ - LPWSTR 字符串到 bool?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58760259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com