0

I am a newbie working with Visual Studio 2019 using MFC C++ App.

I have an Edit Control widget, ID=txtMainDisplay assigned variable CString editBoxText. It has the properties Multiline = True, Want Return = True.

I have a "LOAD" button widget, ID=btnLoad. I have a text file, "test.txt", with contents:

123 ABC
DEF
GH IJK

On the "Load" button click ( OnBnClickedbtnload() ) I have:

string textToString;
ifstream read("test.txt");
getline(read, textToString);
// from what I understand, the Edit Control can only show CStrings
CString stringBackToCString(textToString.c_str());
SetDlgItemText(txtMainDisplay, stringBackToCString)

but this only gets the first line, such as "123 ABC".

I want to get all the lines, I tried:

    do {
        getline(read, textToString);
        CString stringBackToCString(textToString.c_str());
        SetDlgItemText(txtMainDisplay, stringBackToCString);
        if (read.eof())
            break;
    } while (!read.eof());

I think I can see the getline is only getting one line, and I should not have it keep setting the DlgItemText overwriting itself, but can't seem to figure out how to make it display each line in the Edit Control as the test.txt file has in its contents.

0 Answers0