okay so i have a string array that i declared in a header file and I'm trying to write to it but I keep getting this error, "no match for 'operator[]' in 'items[i]'".
void cache()
{
system("cls"); // clear screen
string line;
ifstream items;
items.open("items.txt"); // open file
if(!items.is_open()) // if file failed to open, send user back to start
{
cout << "Product list failed to initialize, teleporting you to the menu." << endl;
system("pause");
menu();
}
for(int i=0; !items.eof(); i++) // for loop to add each item to the 'items' array (defined in globalVars.h)
{
getline(items,line);
items[i] = line; // add entry to array
}
items.close(); //close file
}
What is this all about??? items[i] = line; // add entry to array ???????????
at that point in the code the variable items is the name of the file.
What is the name of your array - is that a global variable called items ??
If so you - try ::items[i] = line; // add entry to array
thanks, helios; it worked. The only problem now is that when it finishes, the program crashes and shows that stupid "send information to microsoft" message.