#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
    vector<int> ints {1, 2, 4};
    vector<string> fruits {"orange", "apple", "raspberry"};
    vector<char> empty;
    
    // Sums all integers in the vector ints (if any), printing only the result.
    int sum = 0;
    for (auto it = ints.cbegin(); it != ints.cend(); it++)
        sum += *it;
    cout << "Sum of ints: " << sum << "\n";
    
    // 输出容器的第一个元素
    cout << "First fruit: " << *fruits.begin() << "\n";
    
    if (empty.begin() == empty.end())
        cout << "vector 'empty' is indeed empty.\n";
}

 

转载于:https://www.cnblogs.com/sea-stream/p/10110747.html

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐