0
点赞
收藏
分享

微信扫一扫

立体相机镜面重建(一)镜面标定

十里一走马 2024-08-12 阅读 29

在C++中当需要对某个容器或数组进行遍历时我们可以使用以下语句,c将会被赋值为s中的元素

	for(char c:s):
	//s可以是任何满足条件的容器或数组
	
	for(int c:s):
	
	for(double c:s):
	
	for(float c:s):
	

在C++中我们来区分std::vector numbers = {1, 2, 3, 4, 5};和std::int numbers[] = {1, 2, 3, 4, 5};区别。

#include <iostream>
#include <vector>

int main() {
    std::vector<int> numbers = {1, 2, 3, 4, 5};

    // 使用范围-based for循环遍历vector<int>
    for (int num : numbers) {
        std::cout << num << " ";
    }

    return 0;
}
#include <iostream>

int main() {
    int numbers[] = {1, 2, 3, 4, 5};

    // 使用范围-based for循环遍历数组
    for (int num : numbers) {
        std::cout << num << " ";
    }

    return 0;
}

区别:

在C++ 中:.size()和.sizeof()区别

举报

相关推荐

0 条评论