void init_song_menu(vector<Song>& songs){
int nsongs = (int) songs.size();
ITEM** items = (ITEM **)calloc(nsongs, sizeof(ITEM *));
ofstream file("songs.txt");
file << flush;
printw("%d ",nsongs);
for(int i = 0; i < nsongs; ++i){
string choice;
stringstream out;
out << i;
out << " ";
out << songs.at(i).get_ID3().title;
choice += out.str();
file << out.str().c_str();
file <<"\n"<<flush;
char* cpy = new char[choice.size()+1];
strcpy(cpy, choice.c_str());
choices.push_back(cpy);
items[i] = new_item(cpy," ");
}
file.close();
items[nsongs-1] = new_item((char *)NULL, NULL);
LSTWINDOW* menu_win = new LSTWINDOW;
menu_win->win = newwin(LINES-2,COLS,2,COLS/4);
menu_win->menu = new_menu((ITEM **)items);
printw("%d", item_count(menu_win->menu));
set_menu_win(menu_win->menu,menu_win->win);
set_menu_sub(menu_win->menu,derwin(menu_win->win,LINES-4,70 ,0,0));
set_menu_format(menu_win->menu,LINES-6,1);
set_menu_mark(menu_win->menu,"*");
wlist.push_back(menu_win->win);
focused = menu_win;
menu_opts_off(menu_win->menu,O_SHOWDESC);
}
我知道该文件已打开,我关闭了该文件。但是,甚至没有创建文件,即使我尝试为它创建文件,它仍然没有写。我写入文件的原因是为了帮助调试为什么只创建了一定数量的菜单条目。 choices是在文件顶部指定的全局向量。