I need to assign each line from the file a number in ascending order and by this number as a key in the map work with a separate line.
The second question is how to use string in stl so that it would be something like an array and refer to each element of the array as word [i].
#include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <map> int main() { setlocale (LC_ALL, ".866"); setlocale (LC_ALL, ".1251"); std::ifstream ifs("file.txt"); std::map<std::string, int> table; std::string word; while(ifs >> word) { table[word]++; } for(std::map<std::string, int>::iterator it = table.begin(); it != table.end(); it++) { std::cout << it->first << " " << it->second << std::endl; } system("pause"); return 0; }