"); subroot = NULL; head = NULL; -6ren">
gpt4 book ai didi

c++ - 为什么我的部分代码没有执行?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:21:15 25 4
gpt4 key购买 nike

我正在使用 Visual C++ 编译我的 Cinema 4D 插件。

    GeDebugOut("-->");
subroot = NULL;
head = NULL;
tail = NULL;
success = PolygonizeHierarchy(source, hh, head, tail, &subroot, malloc);
if (!success) {
/* .. */
}
String str("not set.");
if (subroot) {
GeDebugOut("yes");
str = "yes!";
GeDebugOut("Subroot name: " + subroot->GetName());
}
else {
GeDebugOut("no");
str = "no!";
}
GeDebugOut("Is there a subroot? " + str);
GeDebugOut("<--");

预期输出如下:

-->
yes
Subroot name: Cube
Is there a subroot? yes
<--

(或者与“否”相同。)但是我明白了

-->
yes
<--


为什么这里缺少两张打印品?


这是GeDebugOut的声明。

void GeDebugOut(const CHAR* s,  ...);
void GeDebugOut(const String& s);

String 类是可连接的。它重载了 + 运算符。

String(void);
String(const String& cs);
String(const UWORD* s);
String(const CHAR* cstr, STRINGENCODING type = STRINGENCODING_XBIT);
String(LONG count, UWORD fillch);
friend const String operator +(const String& Str1, const String& Str2);
const String& operator +=(const String& Str);

最佳答案

你需要像使用 printf 一样使用 GeDebugOut:

GeDebugOut("Some message =  %s ", whatever);

其中 whatever 是一个 C 字符串,即它的类型是 char*

由于 GeDebugOut 的重载也接受 String 类型,因此我认为您需要将 unicode 用作:

GeDebugOut(L"Is there a subroot?   " + str);
// ^ note this!

因为我的怀疑是,如果启用了 unicode,那么 CHAR 基本上是 wchar_t,而不是 char。因此,字符串连接不起作用,因为字符串文字不会隐式转换为 String 类型,以传递给 + 重载。

关于c++ - 为什么我的部分代码没有执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11653441/

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