Hello funs2code!
I have the following problem. I need to count the number of occurrences of a concrete word in a text file. I've tried to count the number of occurrences of each word at first.
The following code has no errors but it isn't working! When I type in a command line "project1.exe test.dat cat dog cat dog" the empty string is showed. I've checked if-statements -> right working. Then I've made a conclusion that problem is in for-statement (with iterators).
I tried your code and it seems to work for me. The only thing of consequence which I changed was the headers, instead of #include <iostream.h>
It should be #include <iostream> etc.
I also changed the indentation partly as a matter of preference, but also I found the original code hard to read because of inconsistent indentation.
(I also used setw() to format the output - that was simply my own preference).
Hi @Chervil! I've compiled your recommended code by Builder 6.0 and go in the directory where "project1.exe" is located (in a cmd). Then I've typed "project1.exe test.dat cat dog cat dog". Program has responded me "File test.dat is not found" (according to the line 32 in the code above). Then I've created empty file "test.dat" in the directory where "project1.exe" is located (Folder "CountWords"). I've typed "project1.exe test.dat cat dog cat dog" again and emptiness was shown. What did I realize wrong?
"cat occurred 2 times.
dog occurred 2 times." would shown?
Oh... Hey @Chervil, first off thank you so much, your explanation makes it more clear to me. I've considered that it is necessary to type text in the command line, not in the text file :P
Thanks again!