try
{
CStdioFile file(_T("D:\\thedirectory\\1.txt"), CFile::modeRead);
CString str,mainstr = _T("");
while(file.ReadString(str))
{
mainstr += str;
mainstr += _T("\r\n");
}
CWnd *editwindow = this->GetDlgItem(IDC_EDIT2);
editwindow->SetWindowText(mainstr);
}
catch(CException* e)
{
MessageBox(_T("no such file"));
e->Delete();
}
我设法读取.txt文件,然后用内容更新编辑控制框。效果很好,但现在我只想提取与txt文件分开的第2,3,4,5个单词。有任何想法吗?从txt文件中提取单词,前面有一个分隔符或空格
std :: ifstream有什么问题ifs('n.txt'); while(!ifs.eof()){std :: string s; ifs >> s;/*在这里做些什么* /}? – Hosch250