本文整理汇总了C++中DataFile::Close方法的典型用法代码示例。如果您正苦于以下问题:C++ DataFile::Close方法的具体用法?C++ DataFile::Close怎么用?C++ DataFile::Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataFile
的用法示例。
在下文中一共展示了DataFile::Close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extrn_editors
void extrn_editors() {
vector<editorrec> editors;
DataFile<editorrec> file (syscfg.datadir, EDITORS_DAT);
if (file) {
file.ReadVector(editors, 10);
file.Close();
}
bool done = false;
do {
out->Cls(ACS_CKBOARD);
vector<ListBoxItem> items;
for (size_t i = 0; i < editors.size(); i++) {
items.emplace_back(StringPrintf("%d. %s", i + 1, editors[i].description));
}
CursesWindow* window = out->window();
ListBox list(out, window, "Select Editor", static_cast<int>(floor(window->GetMaxX() * 0.8)),
static_cast<int>(floor(window->GetMaxY() * 0.8)), items, out->color_scheme());
list.selection_returns_hotkey(true);
list.set_additional_hotkeys("DI");
list.set_help_items({{"Esc", "Exit"}, {"Enter", "Edit"}, {"D", "Delete"}, {"I", "Insert"} });
ListBoxResult result = list.Run();
if (result.type == ListBoxResultType::HOTKEY) {
switch (result.hotkey) {
case 'D': {
if (editors.size()) {
string prompt = StringPrintf("Delete '%s'", items[result.selected].text().c_str());
bool yn = dialog_yn(window, prompt);
if (!yn) {
break;
}
auto it = editors.begin();
std::advance(it, result.selected);
editors.erase(it);
}
} break;
case 'I': {
if (editors.size() >= 10) {
messagebox(out->window(), "Too many editors.");
break;
}
string prompt = StringPrintf("Insert before which (1-%d) : ", editors.size() + 1);
size_t i = dialog_input_number(out->window(), prompt, 1, editors.size() + 1);
editorrec e;
memset(&e, 0, sizeof(editorrec));
// N.B. i is one based, result.selected is 0 based.
if (i <= 0 || i > editors.size() + 1) {
break;
} else if (i > editors.size()) {
editors.push_back(e);
edit_editor(editors.back());
} else {
auto it = editors.begin();
std::advance(it, i - 1);
auto new_editor_it = editors.insert(it, e);
edit_editor(*new_editor_it);
}
} break;
}
} else if (result.type == ListBoxResultType::SELECTION) {
edit_editor(editors[result.selected]);
} else if (result.type == ListBoxResultType::NO_SELECTION) {
done = true;
}
} while (!done);
DataFile<editorrec> editors_dat(syscfg.datadir, EDITORS_DAT,
File::modeReadWrite|File::modeBinary|File::modeCreateFile|File::modeTruncate,
File::shareDenyReadWrite);
if (editors_dat) {
editors_dat.WriteVector(editors);
}
}