store shop("shop.txt"); //Calls the constructor (you're probably thinking, "DUH!")
// ... skipping to cStore.h (EDIT: Everything from here down is in "class store")
*Please pretend there's a public: here... I don't want to have
*to re-indent my code 8 spaces. >_<
shopIn.open(userfile.c_str()); //This opens an ifstream with the user-specified file
cout << "Loading Store\n"; //Just for testing purposes; I want to make sure I don't break my code somehow.
LoadStore(); //Uh... loads the store?
if (shopIn.is_open()) shopIn.close();
if (shopOut.is_open()) shopOut.close();
SaveStore(); //Saves the store to a file
string line, key;
shopIn >> line; //Gets a line from shopIn every iteration of the do-while
if ((line != (item + '%' + item)) && (line != "")) //If the line is not the same as the line before...
item = PairSplit(line); //...then parse the line and save the first half here...
item = PairSplit(line, 1); //..and save the second half here.
(item, item)); //Insert the key-value pair into the shopMap.
cout << shopMap[item] << endl; //Debugging cout statement.
} while (!shopIn.eof());
shopOut.open(file.c_str()); //opens an ofstream to the user-specified file
if (!shopMap.empty()) //if the shopMap is not empty
::iterator forIter = shopMap.begin(); //iterator starting at the beginning of the map
::iterator endIter = shopMap.end(); //iterator that stays at the end of the map
if (forIter->first != "" && forIter->second != "") //If forIter does not contain null values...
line = forIter->first + '%' + forIter->second; //...concatenate them using the %...
cout << line << endl;
shopOut << line << endl; //...and print them to the file.
forIter++; //Increment forIter.
} while (forIter != endIter);
Uh... that wasn't as explanatory as I wanted it to be. [sad] Well... basically, when LoadStore is called, it parses the file and splits it into two variables at the '%' character. If the line "lp%Life_Potion$30" was in the file, we'd now have "lp" and "Life_Potion$30", paired and placed into the map. When the shop is saved, the process is reversed (concatenating the key and value with the '%').
Call me a newb, I think I posted this too early in the day. My mind needs to load up on gas. >_> I'm just too excited about getting a journal. :P As a question for anyone reading this, is it acceptable to post twice a day?
EDIT: Forgot to end the source tag. >_<