读取文件在MFC对话框中不起作用,但写入文件

我一直在尝试使用MFC应用程序来读取文本文件中的一行并将其读取的内容用于功能。

我试过使用ifstream和CFile。两种情况下都可以按预期方式写入文件,因此我知道它可以找到该文件。这是我尝试过的:

(使用ifstream)

    std::string temp;
std::ifstream myfile("C:/Users/pranav/testing.txt",std::ios::in); //Read text file for path
myfile.open("C:/Users/pranav/testing.txt");
if (myfile.is_open())
{
    while (getline(myfile, line))
    {
    }
    myfile.close();
}
    else {
        ShellExecute(NULL, _T("open"), _T("cmd.exe"), _T("ls"), _T("C:/Users/pranav/testing.txt"), SW_SHOW);
    }

(使用“ CFile”对话框)

    CStdioFile readFile;
CFileException fileException;
CString strFilePath = _T("C:/Users/pranav/testing.txt");
CString testing58;

if (readFile.Open(strFilePath, CFile::modeRead, &fileException))
{
    readFile.ReadString(testing58);
    while (readFile.ReadString(strLine));

}
else
{
    CString strErrorMsg;
    strErrorMsg.Format(_T("Can't open file %s , error : %u"), strFilePath, fileException.m_cause);
    AfxMessageBox(strErrorMsg);
}
line = (CW2A(strLine.GetString(), CP_UTF8));
readFile.Close();

当我调试它时,字符串的值为空。我也尝试过将文本文件转换为Unicode编码,但这不能解决问题。

非常感谢!