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