一:功能
iota 是给定一个初始元素,然后依次对序列中每个元素进行递增++操作,详见代码一;
atoi 是将字符串转换成整数;atol, atoll 将字符串转换成长整型数 long,long long。
二:用法
#include <iostream> #include <vector> #include <numeric> int main() { std::vector<int> data(9, 0); for (auto v : data) std::cout << v << " "; std::cout << "\n"; //对序列中元素进行累加, -4是初始值 std::iota(data.begin(), data.end(), -4); for (auto v : data) std::cout << v << " "; std::cout << "\n"; //4 -3 -2 -1 0 1 2 3 4 }
#include <stdio.h> #include <stdlib.h> int main(void) { printf("%i\n", atoi(" -123junk")); printf("%i\n", atoi(" +321dust")); printf("%i\n", atoi("0")); printf("%i\n", atoi("0042")); // treated as a decimal number with leading zeros printf("%i\n", atoi("0x2A")); // only leading zero is converted discarding "x2A" printf("%i\n", atoi("junk")); // no conversion can be performed printf("%i\n", atoi("2147483648")); // UB: out of range of int }
到此这篇关于C++ STL iota 和 atoi 用法的文章就介绍到这了,更多相关C++ STL iota 和 atoi内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
来源链接:https://www.jb51.net/program/3252883jz.htm
© 版权声明
本站所有资源来自于网络,仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您(转载者)自己承担!
如有侵犯您的版权,请及时联系3500663466#qq.com(#换@),我们将第一时间删除本站数据。
如有侵犯您的版权,请及时联系3500663466#qq.com(#换@),我们将第一时间删除本站数据。
THE END
暂无评论内容