Write a program which reads in text from standard input a line at a time, and which creates an index (of line number) for the text). Print the results one word per line in the form:
help [3]: 2 3 8
I can read from standard input a line at a time but the other part is what is getting me. I believe you have to use a map to do it but I don't understand maps that well. Any help is appreciated. Thanks.
Help with C++?
Does not look easy. May be you can contact a C++ expert at websites like http://askexpert.info/
Reply:This sounds like a school question. Talk to a teacher. But arrays would work.
Reply:I'm not positive I understand this correctly. So, if someone enters
Foo
bar
blah
Foo
Foo
blah
Then you need to be able to print out that Foo occurs 3 times, on line 1, 4 and 5? and that blah occurs twice, and its line numbers?
If that's it, then you are on the right track with map, except that map only lets you have one instance of a key. So you'd only be able to keep one "Foo" when you'd really like 3 Foo's in there, with their line numbers.
map has a sister called multimap. That one lets you have multiple instances of a key, so you could have "Foo" - 1 "Foo" - 4, "Foo" - 5.
Here's a multimap tutorial, or you can google for others:
http://www.yolinux.com/TUTORIALS/CppStlM...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment