c++ - 带链接字符串的 Ncurses 菜单

标签 c++ ncurses

我想在我的 ncurses 菜单中将字符串链接到如下内容:

/bin
/hello
/home
...

我有一个名为 w_files 的组件 vector ,它有变量 name(bin、hello、home,...),当我这样做时:

chdir(w_actDir.c_str());
this->selected = 0;
unsigned int n_choices = w_files.size();
my_items = (ITEM **)calloc(n_choices+1, sizeof(ITEM *));
for(unsigned int i = 0; i < n_choices; ++i){
    string toShow = w_files[i]->getName();
    my_items[i] = new_item(toShow.c_str(), "");
}


my_menu = new_menu((ITEM**)my_items);

set_menu_mark(my_menu, "");
set_menu_win(my_menu, this->w_window);
set_menu_format(my_menu, LINES-5, 1);
int center = COLS/2;
set_menu_sub(my_menu, derwin(this->w_window, LINES-5, center-5, 3, 1));

post_menu(my_menu);
wrefresh(this->w_window);

没关系,结果看起来:

bin
hello
home
...

但是当将 string toShow = w_files[i]->getName(); 行更改为 string toShow = "/"+ w_files[i]->getName();

结果是: enter image description here

有人可以帮我吗? 谢谢。

最佳答案

实际上,在发表评论后我有了一个答案的想法——最安全的方法是附加到 toShow 字符串。

代码示例:

string toShow = "/";
toShow.append(w_files[i]->getName());

关于c++ - 带链接字符串的 Ncurses 菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17105345/

相关文章:

user-interface - 创建基于终端的安装程序/向导

haskell - 在GHC中指定arch?

c++ - opengl c++ 中的边界填充算法

c++ - Qt中连接不同类的信号槽

c++ - std::bind 不能与 lua_call 互操作

macos - NCurses 和 OS X 10.6 发生了什么变化?

c++ - 按字母顺序排序

c++ - 钳位到 "easy"数字

c - ncurses 和 C- 在 ncurses 窗口中显示 'df' 命令的输出

python - 使用 pythoncurses 更改输入文本的颜色