0

I take words form a text file and add the words to a map with the key being the words and the value being an int for the number of times the word occurs. My problem is that instead of giving me one ordered map, I have two ordered lists of ordered words in one map. Here is a paste from where it starts ordering again (a-z)

  1. Science 1
  2. Spring 1
  3. Studios 1
  4. Tally 1
  5. Test 1
  6. The 1
  7. Then 1
  8. This 1
  9. Turn 1
  10. Visual 1
  11. Write 1
  12. Your 1
  13. a 3
  14. about 1
  15. an 2
  16. and 3
  17. another 1
  18. are 1
  19. as 2
  20. at 1
  21. available 1
  22. be 1
  23. been 1
  24. by 2
  25. can 1
  26. class 3
  27. code 3
  28. collection 1
  29. collection. 1
  30. correct 1
  31. cplusplus 1

My code:

string worder;
while (myfile.good())
{           
    myfile >> worder;   

    ++liner[worder]   //liner is a map
}

myfile.close();
//iterate through map
string outfile = "outfile";
ofstream razzleDazzle;
razzleDazzle.open(outfile);
for (auto mapItem : liner){
    razzleDazzle << mapItem.first << " " << mapItem.second<< endl;
    cout << mapItem.first << " "<< mapItem.second<< endl;
}
//closes output file named "outfile"
razzleDazzle.close();

What gives?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 1
    Capital letters sort before lowercase letters. You should use a case insensitive comparator or normalize the case of your words (eg convert to lowercase) – luqui Apr 18 '15 at 22:35
  • Why do you say "instead of one ordered map"? You have one single map, and those are the strings you're supplying as keys. You don't have two maps. – PaulMcKenzie Apr 18 '15 at 22:37
  • ahh thank you luqui, I didn't even realize the top half was all capitalized :) – ralph lauren Apr 18 '15 at 22:41

0 Answers0