前言

    c++11新增了一个工具,让编译器能够根据初始值的类型推断变量的类型;

    c++11还新增了一种循环,基于范围的for循环,可以对数组或者容器类的每一个元素执行相同的操作;同时,可以使用&表示的引用变量修改每个元素.

代码:

	std::vector<int> responses;
	int label[] = {1, 2, 0, 0,  1, 1, 1,  1, 2, 2 };
	for (auto i : label)
	{
		std::cout << label[i] << " -- "<< i << std::endl;
		responses.push_back(i);
	}

头文件:

#include <opencv2\core\core.hpp>
#include <iostream>
#include <vector>

运行结果:

for-auto使用

注意:auto类型的变量i即是数组中的元素.

做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2023-02-25
猜你喜欢
  • 2021-07-13
  • 2022-12-23
  • 2021-07-17
  • 2022-02-01
  • 2022-12-23
  • 2021-09-17
相关资源
相似解决方案