C++ 之 for 循环 | C++11 for 循环 | 内存 Destory 示例
【摘要】
C++ 之 传统 for 循环 和 C++11 for 循环
#include <iostream>
int main()
{
int arr[4] = {100, 200...
C++ 之 传统 for 循环 和 C++11 for 循环
#include <iostream>
int main()
{
int arr[4] = {100, 200, 300, 400};
std::cout << "传统 for 循环如下" << std::endl;
std::cout << "___________________" << std::endl;
for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
std::cout << arr[i] << std::endl;
}
std::cout << "C++11 遍历 方式 如下" << std::endl;
for (auto num : arr)
{
std::cout << num << std::endl;
}
std::cout << std::endl;
std::cout << std::endl;
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
列表 for 循环 和 auto 字段 推导类型 的使用 示例
对应代码:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
//for循环遍历初始化列表
for (int ch : {1, 2, 3, 4, 5})
{
cout << ch << " ";
}
cout << endl;
//for循环遍历普通数组
char arc[] = "http://oldboy.tech/show.html";
for (char ch : arc)
{
cout << ch;
}
cout << endl;
//for循环遍历 vector 容器
vector<char> myvector(arc, arc + 18);
for (auto ch : myvector)
{
cout << ch;
}
cout << endl;
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
一个 vector 数组 在 return 0 之后 内存 Destory 的示例
文章来源: positive.blog.csdn.net,作者:墨理学AI,版权归原作者所有,如需转载,请联系作者。
原文链接:positive.blog.csdn.net/article/details/115466424
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)