Apr 27, 2014 at 8:11am UTC
I want to read from a file that contains strings and count how many strings of the same name are in the file. Number of strings on file is unknown. For example:
file.txt
--------
apple
apple
orange
red
red
red
output:
-------
file has:
apple 2
orange 1
red 3
Apr 27, 2014 at 5:38pm UTC
I can't run it, it says e is not initialize
Apr 27, 2014 at 5:54pm UTC
Last edited on Apr 27, 2014 at 5:54pm UTC
Apr 27, 2014 at 5:57pm UTC
Don't think my IDE has it, I'm using visual studio 2010.
can it be implemented in way no to use c++11
Apr 27, 2014 at 6:07pm UTC
sure it can be. Replace last loop with this:
1 2
for (std::map<srd::string, int >::const_iterator e = dictionary.begin(); e != dictionary.end(); ++e)
std::cout << e->first << ": " << e->second << '\n' ;
Last edited on Apr 27, 2014 at 6:08pm UTC
Apr 27, 2014 at 6:25pm UTC
great that worked! thank you.