Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179
Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803
Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179
Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
String arrays
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int MAX_ITEMS = 10;
string inventory[MAX_ITEMS];
int numItems = 0;
inventory[numItems++] = "A";
inventory[numItems++] = "B";
inventory[numItems++] = "C";
for (int i = 0; i < numItems; ++i)
cout << inventory[i] << endl;
inventory[0] = "battle axe";
for (int i = 0; i < numItems; ++i)
cout << inventory[i] << endl;
cout << inventory[0] << "" has ";
cout << inventory[0].size() << " letters in it.\n";
if (numItems < MAX_ITEMS)
inventory[numItems++] = "healing potion";
else
cout << "You have too many items and can"t carry another.";
for (int i = 0; i < numItems; ++i)
cout << inventory[i] << endl;
return 0;
}