dimanche 28 mars 2021

Unknown error in inserting values in multimap

I have the following code, where I try to insert values into a multimap of 2 strings, but I keep getting an error that I cannot understand. I've been trying to solve this for hours.

The whole point of the program is to sort the lines of a dictionary based on the automatic sorting of the multimap insertion.

// sort_entries_of_multiple_dictionaries.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <iomanip>
#include <sstream>

// Prototypes
int indexDict(std::multimap<std::string, std::string>& dict);


int main()
{
    std::multimap<std::string, std::string> dict;
    
    if(indexDict(dict) == 0)
        return 0;


}


int indexDict(std::multimap<std::string, std::string>& dict)
{
    std::ifstream inputFile{ "output.txt", std::ios::in };
    std::string currentDictEntry{};
    size_t currentLine{};

    if (!inputFile)
    {
        std::cerr << "input.txt FILE NOT FOUND in the current directory" << std::endl;
        system("pause");
        return 0;
    }

    while (std::getline(inputFile, currentDictEntry))
    {
        //std::cout << currentDictEntry << std::endl; // TO DELETE

        std::string currentWord{};
        size_t delimiterPos = currentDictEntry.find('\t', 0);

        if (delimiterPos == std::string::npos)
            std::cerr << "ERROR. Delimiter \"<b>\" not found in line " << currentLine << std::endl;
        else
        {
            //std::cout << "pos of \\t = " << delimiterPos << std::endl; // TO DELETE
            for (char& ch : currentDictEntry)
            {
                if (ch != '\t')
                {
                    currentWord += ch;
                }
                else
                    break;

            }
            std::cout << currentWord /* << '|' */ << std::endl; // TO DELETE

            auto value = currentDictEntry.substr(delimiterPos, std::string::npos);

            std::cout << "size= " << value.size() << '|' << value << std::endl;

            dict.insert( currentWord, currentWord/*, value*/ );
        }

        if (currentLine == 50) return 0; // TO DELETE


        currentLine++;
    }

    return 1;
}
        if (currentLine == 50) return 0; // TO DELETE


        currentLine++;
    }

    return 1;
}

The error I keep getting is:

unary '++': '_Iter' does not define this operator or a conversion to a type acceptable to the predefined operator

illegal indirection

Aucun commentaire:

Enregistrer un commentaire