C++ Array Error: Access violation reading location 0xC0000005 -
for reason, when try print out array of strings has error:
unhandled exception @ 0x0f767ea6 (msvcp120d.dll) in project1.exe: 0xc0000005: access violation reading location 0x73f6b6ff.
here code generates error:
#include <iostream> #include <string> using namespace std; int main() { const int numitems = 6; string itemnames[numitems] = { "boots", "swords", "helmets", "kittens", "poleaxes", "leggings" }; cout << "*** welcome item shop! ***\n"; (int = 0; < numitems; i++) { cout << itemnames[numitems] << endl; } cout << "**********\n\n"; cout << "what buy?\n"; system("pause"); return 0; }
i using visual studio 2013, way.
for (int = 0; < numitems; i++) { cout << itemnames[numitems] << endl; }
you may want cout << itemnames[i] << endl;
. otherwise itemnames[numitems]
out-of-bound.
Comments
Post a Comment