C++ 的 tuple
等级 4221 次按键
把 string、int 和 double 存入一个 tuple,用 get<索引> 读取,再用结构化绑定拆开。
C++ 代码
// tuple 保存固定数量、类型各异的值1tuple<string, int, double> person("Alice", 25, 5.5);// get<0> 返回第一个元素:Alice2cout << get<0>(person) << endl;// 索引是编译期常量:253cout << get<1>(person) << endl;// 第三个元素:5.54cout << get<2>(person) << endl;5 // 结构化绑定把三个元素复制到具名变量中6auto [name, age, height] = person;// 输出 Alice, 257cout << name << ", " << age << endl;运行结果
Alice 25 5.5 Alice, 25
可以用这段代码练习打字。成绩不会计入排行榜。
这段代码中的符号
这段 C++ 代码中需要输入的符号及其出现次数。
<× 24,× 7;× 6"× 4(× 4)× 4>× 4.× 1[× 1]× 1