Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve(docs): beginner > arrays #195

Merged
merged 5 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```cpp
#include <iostream>
#include <string>
#include <vector>

int main()
{
using std::vector, std::string, std::cout;

vector<string> playerNames = {
"HappyBanana",
"AngryCrab",
"SadWolf",
};

// Adding a new player:
// highlight-next-line
playerNames.push_back("WickedWitch");

// Printing the name of player with index 3
cout << "Name of the player with index 3: " << playerNames[3];
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ int main()
{
using std::vector, std::string, std::cout;

vector< string > playerNames(3);

// Setting names of the players
playerNames[0] = "HappyBanana";
playerNames[1] = "AngryCrab";
playerNames[2] = "SadWolf";
vector<string> playerNames = {
"HappyBanana",
"AngryCrab",
"SadWolf",
};

// Adding a new player:
playerNames.push_back("WickedWitch");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ int main()
{
using std::vector, std::string, std::cout;

vector< string > playerNames(3);

// Setting names of the players
playerNames[0] = "HappyBanana";
playerNames[1] = "AngryCrab";
playerNames[2] = "SadWolf";
vector<string> playerNames = {
"HappyBanana",
"AngryCrab",
"SadWolf",
};

// Adding a new player:
playerNames.push_back("WickedWitch");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ int main()
{
using std::vector, std::string, std::cout;

vector< string > playerNames(3);

// Setting names of the players
playerNames[0] = "HappyBanana";
playerNames[1] = "AngryCrab";
playerNames[2] = "SadWolf";
vector<string> playerNames = {
"HappyBanana",
"AngryCrab",
"SadWolf",
};

// Adding a new player:
playerNames.push_back("WickedWitch");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
```cpp
#include <iostream>
#include <string>
#include <vector>

int main()
{
using std::vector, std::string, std::cout;

// highlight-start
vector<string> playerNames = {
"HappyBanana",
"AngryCrab",
"SadWolf",
};
// highlight-end

// Printing the name of the first player:
cout << "Name of the first player: " << playerNames[0];
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ int main()
{
using std::vector, std::string, std::cout;

vector< string > playerNames(3);

// Setting names of the players
playerNames[0] = "HappyBanana";
playerNames[1] = "AngryCrab";
playerNames[2] = "SadWolf";
vector<string> playerNames = {
"HappyBanana",
"AngryCrab",
"SadWolf",
};

// Adding a new player:
playerNames.push_back("WickedWitch");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ int main()
{
using std::vector, std::string, std::cout;

vector< string > playerNames(3);

// Setting names of the players
playerNames[0] = "HappyBanana";
playerNames[1] = "AngryCrab";
playerNames[2] = "SadWolf";
vector<string> playerNames = {
"HappyBanana",
"AngryCrab",
"SadWolf",
};

// highlight-next-line
cout << "The array contains " << playerNames.size() << " elements\n";
Expand All @@ -26,10 +25,6 @@ int main()
playerNames.insert(playerNames.begin() + 1, "BadPenguin");

// Erase the first element:
// highlight-next-line
playerNames.erase(playerNames.begin() + 0);

// highlight-next-line
cout << "The array contains " << playerNames.size() << " elements\n";
}
```
Loading