当前位置: 首页>>代码示例>>C++>>正文


C++ Notebook::remove方法代码示例

本文整理汇总了C++中Notebook::remove方法的典型用法代码示例。如果您正苦于以下问题:C++ Notebook::remove方法的具体用法?C++ Notebook::remove怎么用?C++ Notebook::remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Notebook的用法示例。


在下文中一共展示了Notebook::remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main() {
    Notebook my;

    my.export_notes("notebook");

    cout << "------------------\n"
        << "Select action:\n"
        << "1) Add note\n"
        << "2) Find note\n"
        << "3) Remove note\n"
        << "4) Show all notes\n"
        << "q) Close notebook\n"
        << "------------------\n";    


    char ans;
    
    ans = cin.get();
    while (((ans < '1') || (ans > '4')) && (ans != 'q')) {
        if (ans != '\n')
            while (cin.get() != '\n');
        cout << "Please, enter correct command: ";
        ans = cin.get();
    }
    while (cin.get() != '\n');
    
    while (tolower(ans) != 'q') {
        switch (ans) {
            case '1' : {
                char name[100] = {};
                cout << "Enter name: ";
                cin.getline(name, 99);
                char phone[100] = {};
                cout << "Enter phone: ";
                cin.getline(phone, 99);
                if (!my.find(name))
                    my.add(name, phone);
                else {
                    cout << "Note " << name << " is already exist, replace? [y/n]: ";
                    char ch;
                    ch = cin.get();
                    ch = tolower(ch);
                    if (ch != '\n')
                        while (cin.get() != '\n');
                    while (ch != 'y' && ch != 'n') {
                        cout << "Enter y or n: ";
                        ch = cin.get();
                        ch = tolower(ch);
                        if (ch != '\n')
                            while (cin.get() != '\n');
                    }

                    if (tolower(ch) == 'y')
                        my.add(name, phone);
                }
                break;
            }
            case '2' : {
                char name[100] = {};
                cout << "Enter name: ";
                cin.getline(name, 99);
                char const * res = my.find(name);
                if (res == nullptr)
                    cout << name << " not found\n";
                else
                    cout << name << ": " << res << endl;
                break;
            }
            case '3' : {
                char name[100] = {};
                cout << "Enter name: ";
                cin.getline(name, 99);
                if (!my.find(name))
                    cout << name << " not found\n";
                else {
                    cout << "Confirm removal " << name << " [y/n]: ";
                    char ch;
                    ch = cin.get();
                    ch = tolower(ch);
                    if (ch != '\n')
                        while (cin.get() != '\n');
                    while (ch != 'y' && ch != 'n') {
                        cout << "Enter y or n: ";
                        ch = cin.get();
                        ch = tolower(ch);
                        if (ch != '\n')
                            while (cin.get() != '\n');
                    }

                    if (tolower(ch) == 'y')
                        my.remove(name);
                    cout << "Removal " << name << " complete\n";
                }
                break;
            }
            case '4' :
                my.show_all();
        }

        cout << "\n------------------\n"
//.........这里部分代码省略.........
开发者ID:DmitrySalnikov,项目名称:Notebook,代码行数:101,代码来源:menu.cpp


注:本文中的Notebook::remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。