C++ 标准库笔记

                     

贡献者: addis

1. string

   详见 “C++ 字符串笔记”。

2. vector

   更多容器详见 “C++ 标准库常用容器

3. ctime

4. algorithm

5. stdlib

6. std::variant

#include <variant>
using namespace std;

using Operand = variant<int, double>;

Operand performOperation(const Operand& left,
    const Operand& right, const string& op) {
    // Visitor that applies the operation
    return visit([&](auto&& arg1, auto&& arg2) -> Operand {
        if (op == "+") return arg1 + arg2;
        else if (op == "-") return arg1 - arg2;
        else if (op == "*") return arg1 * arg2;
        else if (op == "/") {
            if (arg2 == 0) {
                cout << "Cannot divide by zero!" << endl;
                return 0;
            }
            return arg1 / arg2;
        }
        else {
            cout << "Unsupported operation" << endl;
            return 0;
        }
    }, left, right);
}

7. std::any


致读者: 小时百科一直以来坚持所有内容免费,这导致我们处于严重的亏损状态。 长此以往很可能会最终导致我们不得不选择大量广告以及内容付费等。 因此,我们请求广大读者热心打赏 ,使网站得以健康发展。 如果看到这条信息的每位读者能慷慨打赏 10 元,我们一个星期内就能脱离亏损, 并保证在接下来的一整年里向所有读者继续免费提供优质内容。 但遗憾的是只有不到 1% 的读者愿意捐款, 他们的付出帮助了 99% 的读者免费获取知识, 我们在此表示感谢。

                     

友情链接: 超理论坛 | ©小时科技 保留一切权利