Answers for "cpp std::array"

C++
1

array template c++

#include <iostream>
#include <array>
using namespace std;

int main () {
    const int size = 5;
    array<int, size> numbers; // create stl array template
    array<int, size> :: iterator NUMBER_ITERATOR; // declare iterator that points to stl template numbahs

    NUMBER_ITERATOR = numbers.begin(); // points iterator to first element in array template 
    cout << "Please fill the array: n";
    for(;NUMBER_ITERATOR != numbers.end(); NUMBER_ITERATOR++) cin >> *NUMBER_ITERATOR; // enter the value for each element one-by-one

    NUMBER_ITERATOR = numbers.begin(); // reset the pointer to first element
    cout << "Displaying array: n"; 
    for(;NUMBER_ITERATOR != numbers.end(); NUMBER_ITERATOR++) cout << *NUMBER_ITERATOR << "n"; // prints out value for each
    cout << endl;

    return 0;
}
Posted by: Guest on December-09-2020
0

std array c++

#include <bits/stdc++.h>
using namespace std;
 
main() {
    array<string, 3> a1{"a", "b", "c"};
 	array<int, 5> a2; 
 	cout<<a1[0]<<endl;
    //size of array
    cout<<a1.size()<<endl;   
    //Sorts the elements
	sort(a1.begin(), a1.end());
    for(auto& i: a1) {
    	cout << i << ' ';
    }
}
Posted by: Guest on May-31-2021

Browse Popular Code Answers by Language