#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";
}

 

相关文章:

  • 2021-11-28
  • 2021-07-04
  • 2021-06-11
  • 2021-09-23
  • 2021-06-08
  • 2021-08-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-11-27
  • 2021-11-28
相关资源
相似解决方案