STL Map help

Hey can anyone explain this because I am completely lost on what my teacher wants us to do for a map. We are doing a madlib type project. I have sent him a email about 4-5 days ago and he hasn't sent me a response back. I am just stuck on this part right now. I hope I can explain this well enough so someone can understand and lead me on the right direction. There is probably going to be a lot of text and Im sorry if it doesn't make much sense. I will be trying my best to explain it, but thanks if you can help.

So our teacher wants us to read a file and find the tokens "@" and find one and then find the next one and read in between them and store them into a map. Then get the userInput from what tokens it find and then read the file again and find the tokens again and put the userInput in for the tokens it find.

I have it check to see if the file can open and it then it reads oneLine at a time. Then I have it find the start "@" then the end "@" and get the substring from whats in between those two and then stores it in the map. Then keeps reading the line, if it finds another one on the line it does the same thing, then goes to the next line and repeats until there is nothing left in the file.


He gave us a practice a text for us to read:

# test madlib "To be or not to be"
#
#

To @BE@, or not to @BE@, that is the @noun@:
Whether 'tis @NOBLER@ in the @MIND@ to @verb@
The @nouns@ and @nouns@ of @adj@ Fortune,
Or to take @nouns@ against a @noun@ of @nouns@
wshakespeare@@theglobe.com

Take from the original, Shakespeare's "Hamlet", Act 3, Scn. 1:

To be, or not to be, that is the question:
Whether 'tis Nobler in the mind to suffer
The Slings and Arrows of outrageous Fortune,
Or to take Arms against a Sea of troubles


@end-of-story@

@BE@ verb
@NOBLER@ An adjective ending in -er
@MIND@ part of the body

1
2
3
4
5
6
7
8
9
10
/* I had it like this */

subMap["BE"] = "Enter a Verb";
subMap["noun"] = "Enter a Noun";
subMap["NOBLER"] = "Enter an Adjective ending in -er";
subMap["MIND"] = "Enter a Part of the body";
subMap["nouns"] = "Enter a Plural noun";
subMap["adj"] = "Enter a Adjective";
subMap["end-of-story"] = "End of the story";


I had the program working pretty good when I had it like this, but I was in class and he doesn't want it hard coded. So he changed it. I mean it make sense, but it only has the first part in the map and the second is blank

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
/* This actually stores each token it finds in the text 
So if the token was already found it doesn't do anything, but if it wasn't
found it adds it to the map.*/
string token;
string::size_type start(0);
string::size_type end;
	
end = oneLine.find( "@", start);
	
while (end != string::npos)
{
	token = oneLine.substr( (start), (end - start) );

	start = end + 1;
	end = oneLine.find("@", start);
}

if (theMap.find(token) != theMap.end())
{

}
else
{
	theMap[ token ] = "";
}


So I can make it print out the map.
It will have:
BE
MIND
noun
adj
NOBLER
etc..

But what I actually don't understand is how would you even add the second part to the map??? Because it is stored in the variable token and then stored into the map. So how would you even add the second part to ask the question like "Enter a verb" because realistically we wouldn't really know what the token is. He just wants us to find it and then prompt the user, but you can't really do that because you can't really find what it is.

I don't know if any of that made sense, but if it did I would appreciate the help. I am just frustrated with it right now. Thanks again if you can help!!!!


Perhaps I'm not understanding you, but why can't you prompt the user after you've failed to find a match for your token? e.g.
1
2
3
4
if (theMap.find(token) == theMap.end()) 
{
    // TODO: Ask the user
}
Topic archived. No new replies allowed.