15,980
社区成员
发帖
与我相关
我的任务
分享
CStdioFile infile;
if (!infile.Open(L"interpreter.txt", CStdioFile::modeRead))
{
AfxMessageBox(L"can not open file");
}
CString str;
while (infile.ReadString(str))
AfxMessageBox(str);
infile.Close();
char* old_locale = _strdup( setlocale(LC_CTYPE,NULL) );
setlocale( LC_CTYPE, "chs" );//设定<ctpye.h>中字符处理方式
setlocale( LC_CTYPE, old_locale );
free( old_locale );//还原区域设定
typedef pair<int, wstring> worditem;//
typedef vector<worditem> worditems;
typedef pair<int, worditems*> field;//first of the pair is not wstring
typedef vector<field> fields;
typedef pair<int, fields*> msg;
typedef vector<msg> msgs;
typedef pair<int, msgs*> channel;
typedef vector<channel> channels;
bool CInterpreter::ProcessLine(CString str)
{
AfxMessageBox(str);
int value;
wchar_t means[256]={L'\0'};
#ifdef _DEBUG
wcout << L"\t\t" << str << endl;
#endif
// AfxMessageBox(str.c_str());
// _stscanf(str.c_str(), L"%*s%d%s", &value, means);
if (str[0] == L';')
{
if (str[1] == L';')
{
if (str[2] == L';')
{
if (str.GetLength() > 3)
{
//信道标志开始
if (m_pMsgs == NULL)
{
m_pMsgs = new msgs;
_stscanf((LPCTSTR)str, L"%*s%d", &value);
m_channels.push_back(make_pair(value, m_pMsgs));
}
}
else
{
//信道标志结束
/*m_channels.push_back(make_pair(value, m_pMsgs));
m_pMsgs = new msgs;*/
m_pMsgs = NULL;
}
}
else
{
if (str.GetLength() > 2)
{
//消息标志开始
m_pFields = new fields;
_stscanf((LPCTSTR)str, L"%*s%d", &value);
m_pMsgs->push_back(make_pair(value, m_pFields));
}
else
{
//消息标志结束
m_pFields = NULL;
}
}
}
else
{
if (str.GetLength() > 1)
{
//域标志开始
m_pWorditems = new worditems;
_stscanf((LPCTSTR)str, L"%*s%d", &value);
m_pFields->push_back(make_pair(value, m_pWorditems));
}
else
{
//域标志结束
m_pWorditems = NULL;
}
}
}
else
{
//域的具体值对应的具体解释
// m_pFields->push_back(make_pair(value, wstring(means)));
//int i = _stscanf(str.c_str(), L"%d", &value);
//wcout << i << L" " << str.substr(str.find(L";")) << endl;
//_stscanf(str.c_str(), L"%d%s", &value, means);
value = _wtoi((LPCTSTR)str);
m_pWorditems->push_back(make_pair(value, wstring((LPCTSTR)str.Mid(str.Find(L";") + 1))));
}
// wcout << L"value= " << value << L" means=" << &means[0] << endl;
// cin.clear();
return true;
}
bool CInterpreter::Configure(wstring strFile)
{
// wifstream infile(L"E:\\GotaBrowser\\release\\interpreter.txt", wios::in);
CStdioFile infile;
if (!infile.Open(L"E:\\GotaBrowser\\release\\interpreter.txt", CStdioFile::modeRead))
{
#ifdef _DEBUG
std::wcerr << L"wrong, can not open the interpreter.txt file, pls check it." << std::endl;
#endif
AfxMessageBox(L"打开interpreter.txt文件失败");
return false;
}
/*
m_pMsgs = new msgs;
m_pFields = new fields;
m_pWorditems = new worditems;
*/
/* wstring str;
while (getline(infile, str))//, L"\n"))
{
ProcessLine(str);
}*/
CString str;
infile.Read(str.GetBufferSetLength(infile.GetLength()/2), infile.GetLength());
AfxMessageBox(str);
int cur, last = 0;
while ( (cur = str.Find(L"\r\n", last)) != -1)
{
ProcessLine(str.Mid(last, cur - last));
last = cur + 2;
}
ProcessLine(str.Mid(last));
infile.Close();
return true;
}
void CMfctestDlg::OnButton1()
{
CStdioFile infile;
if (!infile.Open(L"C:\\x.txt", CStdioFile::modeRead))
{
AfxMessageBox(L"can not open file.");
return;
}
CString str;
while (infile.ReadString(str))
{
AfxMessageBox(str);
}
infile.Close();
}
CStdioFile infile;
if (!infile.Open("interpreter.txt", CStdioFile::modeRead))
{
AfxMessageBox("can not open file");
}
CString str;
while (infile.ReadString(str))
AfxMessageBox(str);
infile.Close();