gpt4 book ai didi

c++ - 使用结构中的 ncurses 扩展字符

转载 作者:行者123 更新时间:2023-11-30 05:21:54 25 4
gpt4 key购买 nike

我正在尝试显示从结构中提取的 ncurses 扩展字符。

当我尝试使用时:

#include <ncurses.h>
struct TEST_STRUCT
{
char nCharacter; // Where I want to store variable for printed character
short nTestNumber; // Other stuff in struct
};
TEST_STRUCT sTestData[] = {
{ '.', 1 }, // Period
{ ',', 2 }, // Comma
{ ACS_VLINE, 1 } // Vertical Line
};
int main(void)
{
initscr();
clear();
for( int n = 0; n < 3; n++)
{
addch(sTestData[n].nCharacter); // print the characters in the struct
}
refresh();
endwin();
return 0;
}

ACS_VLINE 字符显示不正确,但经过一番折腾,我发现了以下工作:

#include <ncurses.h>
struct TEST_STRUCT
{
int nCharacter; // Where I want to store variable for printed character
short nTestNumber; // Other stuff in struct
};
TEST_STRUCT sTestData[] = {
{ '.', 1 }, // Period
{ ',', 2 }, // Comma
{ 4194424, 1 } // Vertical Line
};
int main(void)
{
initscr();
clear();
for( int n = 0; n < 3; n++)
{
addch(sTestData[n].nCharacter); // print the characters in the struct
}
endwin();
return 0;
}

将数值存储在 int 中似乎是错误的,但它确实有效。我应该怎么做才能“正确”地做到这一点。

最佳答案

第一个示例的问题是符号 ACS_VLINE 是数组中的一个条目,它不是静态初始化的(它的实际内容取决于 initscr)。奇怪的是,g++ 不会对此发出警告,但 gcc -Wall 会发出警告。

定义如下:

#define NCURSES_ACS(c)  (acs_map[NCURSES_CAST(unsigned char,c)])

#define ACS_VLINE NCURSES_ACS('x') /* vertical line */

第二种情况下的常量不同,相当于 A_ALTCHARSETx 的组合:

#define NCURSES_ATTR_SHIFT       8
#define NCURSES_BITS(mask,shift) ((mask) << ((shift) + NCURSES_ATTR_SHIFT))

#define A_ALTCHARSET NCURSES_BITS(1UL,14)

正如 changelog from 2003 中所暗示的那样,自 2000 年代初以来,这就是一个区别。 .

关于c++ - 使用结构中的 ncurses 扩展字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39881521/

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