Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 带有链接字符串的Ncurses菜单_C++_Ncurses - Fatal编程技术网

C++ 带有链接字符串的Ncurses菜单

C++ 带有链接字符串的Ncurses菜单,c++,ncurses,C++,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(

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

/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);
但是当更改line
string toShow=w_files[i]->getName()时
字符串toShow=“/”+w_文件[i]->getName()

结果是:

有人能帮我吗?
谢谢。

事实上,在发表评论后,我有了一个答案的想法-最安全的方法是在
toShow
字符串后面加上后缀

代码示例:

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

你应该得到警告,如果不是错误的话。这是因为
“/”
不是
std::string
,所以不能在串联表达式中首先使用它。如果在尝试添加两个指针时,
getName
不返回
std::string
,情况会更糟。尝试改为
std::string(“/”+…
@JoachimPileborg:不工作。。。我没有收到任何警告,我编译了巫婆墙书呆子。。。方法getName返回stringWhat在不使用“/?@Losiowaty的情况下存储目录名对您来说重要吗?是的,因为它是一个简单的文件管理器,在复制或移动时会出现问题..也不工作。。。但是,我已经这样解决了:
my_items[i]=new_item(“/”,w_files[i]>getName().c_str())
我知道这不是最好的选择,但它很有效……好吧,我已经签入了文档,而且您的第一种方法(也是我的解决方案)似乎没有发挥作用,因为
new\u item
不会复制它传递的字符串,它只存储指向它的指针,所以您必须确保内存在items的整个生命周期内都是有效的,您第一次尝试在for循环中创建字符串,这意味着它在循环结束后也被销毁。我很确定,由于这个原因,传递“/”的方式也容易出错。
string toShow = "/";
toShow.append(w_files[i]->getName());