[Solved] How to extract a multiline text segment between two delimiters under a certain heading from a text file using C++ [closed]


After taking a closer look at reading text files in C++, I settled on this passable but most likely far from ideal solution:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
    string TextFile;
    cout << "Enter the wordlist to search:" << "\n";
    getline(cin, TextFile);

    string Search;
    int Offset = 0;
    int Offset2 = 0;
    string Line;
    ifstream iEnglishVocabulary;
    iEnglishVocabulary.open(TextFile + ".txt");

    string Word;
    string EntryEnd = "________________________________________";
    int Dummy = 0;
    bool PassingEntry = 0;
    bool WordFound = 0;

    //Input

    cout << "Enter the word:" << endl;
    getline(cin, Word);

    Search = "<>" + Word + ":";
    if (iEnglishVocabulary.is_open())
    {
        while (!iEnglishVocabulary.eof())
        {
            getline(iEnglishVocabulary, Line);
            Offset = (Line.find(Search, 0));
            Offset2 = (Line.find(EntryEnd, 0));
            if (Offset != string::npos)
            {
                PassingEntry = 1;
                WordFound = 1;
                cout << endl << endl;
            }
            if (PassingEntry == 1)
            {
                if (Offset2 != string::npos)
                {
                    PassingEntry = 0;
                    cout << Line << endl;
                }
                else
                {
                    cout << Line << endl;
                }
            }
        }
        if (WordFound == 0)
        {
            cout << "The word is not in the list" << endl;
        }
    }

    //Output

    cin >> Dummy;

    iEnglishVocabulary.close();

    return 0;
}

This solution does include the heading and bottom line also, as I found that worked better. If anyone has a better solution I’m sure posterity would be grateful.

solved How to extract a multiline text segment between two delimiters under a certain heading from a text file using C++ [closed]