我想让我的ncurses菜单中的字符串链接到如下内容:
/bin
/hello
/home
...我有名为w_files的组件的向量,它们具有变量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();时
结果是:

有人能帮帮我吗?谢谢。
发布于 2013-06-14 19:11:08
实际上,在发表了评论后,我有了一个答案--最安全的方法是附加到toShow字符串中。
代码示例:
string toShow = "/";
toShow.append(w_files[i]->getName());https://stackoverflow.com/questions/17105345
复制相似问题