string arrays cmd issue

Hello there my fellow programmers.Since I fell in love with this forum and the users,I came to ask yet another question,if you can spare 5 minutes to look at it.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

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

int main()
{

  const int MAX_ITEMS = 10;
  string inventory[MAX_ITEMS]; // you can only carry 10 items.
  
  int number_items = 0;
  
  inventory[number_items++] = "sword"; 
  inventory[number_items++] = "shield";
  inventory[number_items++] = "armor";
  // by this time,the number of item is 3,I believe.

  cout << "your items:" << endl;
  
  for (int i = 0;i < number_items;++i)
  {
      cout << inventory[i] << endl;
      } // prints out all the items in inventory
   




system("pause");
return 0;
}




If anyone has read Micheal Dawson's 'beginning C++ with game programming',that is where I got it from.Anyways,

the problem with this is that I believe there is no problem with the actually code,but the cmd itself.When I try to run the program,the cmd opens in a blank,and suddenly the error window appears that says 'the *insert file name here* stopped working.'That is really funny because it doesnt create such error with other programs.If anyone knows how to deal with this,please let me know.
Topic archived. No new replies allowed.