Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <iostream> | ||
#include <array> | ||
|
||
using namespace std; | ||
|
||
/* | ||
Arrays < Vectors. Flexibility > Not Flexible | ||
*/ | ||
|
||
|
||
int main() { | ||
string myArray[3]; // define new array - data-type string, element size of 3 | ||
// assigning elements to index 0, 1, and 2 | ||
myArray[0] = "C++"; | ||
myArray[1] = "Has"; | ||
myArray[2] = "Arrays"; | ||
// printing out each element | ||
cout << myArray[0] << " " << myArray[1] << " " << myArray[2] << endl; | ||
|
||
for (const string& x: myArray) { // looping through the array | ||
cout << x << " "; // printing out each element seperated by a space | ||
} | ||
cout << "\n"; | ||
|
||
// Making arrays a different way | ||
// using the template format | ||
array<int, 5> myOtherArray = {1, 2, 3, 4, 5}; | ||
// same process of getting elements, just don't need to define elements after as already done as such | ||
for (const int& x : myOtherArray) { // looping through the array again | ||
cout << x << " "; | ||
} | ||
cout << "\n"; | ||
} |