I am trying to do a mad libs type of thing where I have a story(Story.dat) and other data files with the words (nouns.dat, verbs.dat, etc.). The words to be raplaced in the story are marked with an * at the beginning and end (ex. *noun*). My problem is when I try to remove the words that are marked and replace them with a random choice from one of the words. I can't get it to work. So far I have only written the code to replace nouns, here it is in pastebin. http://pastebin.com/rU10yy1D
Do you think you guys could point out what I am doing wrong?
For the sake of argument, let's say you haven't tried actually using more than just one ifstream variable and attempting to open the files over the top of each other without closing them first, and go ahead and try what I just described.
.
You are trying to stuff all of the file inputs into the same variable without closing the inputs.
I think you should use more than one ifstream variables (one for each concurrently open file).
int main(){
// Variables
ifstream finStory("Story.dat"), finNoun("noun.dat"), finNounP("nounp.dat");
// Do stuff
return 0;
}
However, if you want to open and close noun or nounp only when it's needed, that's fine. Personally, if I'm going to be paging it multiple times, I'm just going to hold it open until I'm finished with it.
Alright, we have made progress. It works a little bit. Only a few words are being replaced. The code is below and the output is here: http://oi40.tinypic.com/ixfw47.jpg
It looks to me, from first glance, that you don't have *nouns* defined, and your definition of *verbp* doesn't have a closing asterisk. There may be other minor overlooked errors of similar type.
Just curious, what's the point of the rand? My instinct says it's not necessary at all; you may be reaching the end of your input files before you actually get anything useful from them.