0

So i'm trying to read a series of strings from a file, separated by the tab character, then store them into a struct. The problem i'm having is that two of these strings contain space(s), heck one is a full blown sentence. So the usual (file >>) operation won't work. I have an idea how I can do it but it's wholly inefficient. Any ideas how i can do this?

Sample Data: Book noun. A collection of pages, written or blank.

This is the output i want: Book noun. A collection of pages, written or blank.

This is the output i'm getting: Book noun. A

This is my code so far:

void readFile(string filename)
{
    Node::Word fw;
    try
    {
        std::ifstream file(filename, std::ios::in);
        if (file.fail())
        {
            throw std::runtime_error("Error reading files!");
        }
        string word, description, pos;
        while (file >> word >> pos >> description)
        {
            fw.word = word;
            fw.partofspeech = pos;
            fw.meaning = description;
            insertElement(fw);
        }
        file.close();
    }
    catch (std::runtime_error & e)
    {
        std::cerr << e.what() << std::endl;
    } 
}
Davii
  • 1

0 Answers0