求教:结合combobox和listbox设计文本文件保存/读取程序 文本文件中有两行第一行是combobox中的项目,以“,”分割项目,如:111,222,333判断出换行后第二行是listbox中的项目,以“,”分割项目,如:111,aaa,ccc求教高手这样设计这段程序? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CStdioFile file; if( !file.Open("c:\\1.txt", CFile::modeRead) ) { AfxMessageBox("can not open file!"); return; } CString strLine; int nLine=0; CStringArray arr[2]; while(file.ReadString(strLine)) { nLine++; for(int i=0; i<arrChapter.GetSize(); i++) { char *ss=strLine.GetBufferSetLength(strLine.GetLength()); char *p; for ( p=strtok(ss, ","); p!=NULL; p=strtok(NULL, ",") ) { arr[nLine].Add(p); } } file.Close(); for(int i=0; i<arr[0].GetSize(); i++) { m_combo.AddString(arr[0][i]); m_listbox.AddString(arr[1][i]); } 三,这个是读文件的噢,程序中好多编译错误~for(int i=0; i<arrChapter.GetSize(); i++)这句话中的arrChapter没定义? for(int i=0; i<arrChapter.GetSize(); i++)这句代码多余的,,删除 程序运行的时候出错,不能运行,编译通过!还有,问个问题,为什么下面这段代码要放在file.close();后面呢?for(int i=0; i<arr[0].GetSize(); i++) { m_combo.AddString(arr[0][i]); m_listbox.AddString(arr[1][i]); } CStdioFile file; if( !file.Open("c:\\1.txt", CFile::modeRead) ) { AfxMessageBox("can not open file!"); return; } CString strLine; int nLine=0; CStringArray arr[2]; while(file.ReadString(strLine)) { char *ss=strLine.GetBufferSetLength(strLine.GetLength()); char *p; for ( p=strtok(ss, ","); p!=NULL; p=strtok(NULL, ",") ) { arr[nLine].Add(p); } nLine++; } file.Close(); for(int i=0; i<arr[0].GetSize(); i++) { m_combo1.AddString(arr[0][i]); m_listbox.AddString(arr[1][i]); }我运行过了,正确的 你那1.txt文件里的格式是怎样的?我出错运行不起来估计就是和你那文件里的格式不对~我那格式是这样的:111,222,AAA 222,333,444 原来的代码有误,刚才贴的才对。原来代码中,nLine++;的位置不对。。 CStdioFile file; if( !file.Open("c:\\1.txt", CFile::modeRead) ) { AfxMessageBox("can not open file!"); return; } CString strLine; int nLine=0; CStringArray arr[2]; while(file.ReadString(strLine)) { strLine.TrimLeft(); strLine.TrimRight(); if( strLine.IsEmpty() ) continue; char *ss=strLine.GetBufferSetLength(strLine.GetLength()); char *p; for ( p=strtok(ss, ","); p!=NULL; p=strtok(NULL, ",") ) { arr[nLine].Add(p); } nLine++; } file.Close(); for(int i=0; i<arr[0].GetSize(); i++) { m_combo1.AddString(arr[0][i]); m_listbox.AddString(arr[1][i]); } OpenGL中颜色问题 VC中添加类的方法有二种有何区别 VC与C混合编译后,各自的变量互不认识的问题。 紧急求救:CListView的三角箭头? 【求助】单文档程序信号采集程序,界面控件的图层问题。谢谢。 关于找不到***.DLL的问题 禁止光驱弹出 请问加上什么头文件,可以调用函数:AfxFullPath,AfxGetFileTitle? 实在是太奇怪了,请帮我解决这个问题,50分 怎样先后调用两个应用程序? 在打印前 怎样得到所设定的纸张的大小 横纵 啊??? **如何把pdf格式的文件内容转化生成一个相应的bmp,gif....等图片格式**
CString strLine;
int nLine=0;
CStringArray arr[2]; while(file.ReadString(strLine)) {
nLine++; for(int i=0; i<arrChapter.GetSize(); i++) { char *ss=strLine.GetBufferSetLength(strLine.GetLength()); char *p; for ( p=strtok(ss, ","); p!=NULL; p=strtok(NULL, ",") ) { arr[nLine].Add(p); } }
file.Close();
for(int i=0; i<arr[0].GetSize(); i++)
{
m_combo.AddString(arr[0][i]);
m_listbox.AddString(arr[1][i]);
}
for(int i=0; i<arrChapter.GetSize(); i++)这句话中的arrChapter没定义?
还有,问个问题,为什么下面这段代码要放在file.close();后面呢?
for(int i=0; i<arr[0].GetSize(); i++)
{
m_combo.AddString(arr[0][i]);
m_listbox.AddString(arr[1][i]);
}
{
AfxMessageBox("can not open file!");
return;
} CString strLine;
int nLine=0;
CStringArray arr[2]; while(file.ReadString(strLine))
{
char *ss=strLine.GetBufferSetLength(strLine.GetLength());
char *p;
for ( p=strtok(ss, ","); p!=NULL; p=strtok(NULL, ",") )
{
arr[nLine].Add(p);
}
nLine++;
}
file.Close(); for(int i=0; i<arr[0].GetSize(); i++)
{
m_combo1.AddString(arr[0][i]);
m_listbox.AddString(arr[1][i]);
}我运行过了,正确的
我那格式是这样的:111,222,AAA
222,333,444
刚才贴的才对。原来代码中,nLine++;的位置不对。。
{
AfxMessageBox("can not open file!");
return;
} CString strLine;
int nLine=0;
CStringArray arr[2]; while(file.ReadString(strLine))
{
strLine.TrimLeft();
strLine.TrimRight();
if( strLine.IsEmpty() )
continue;
char *ss=strLine.GetBufferSetLength(strLine.GetLength());
char *p;
for ( p=strtok(ss, ","); p!=NULL; p=strtok(NULL, ",") )
{
arr[nLine].Add(p);
}
nLine++;
}
file.Close(); for(int i=0; i<arr[0].GetSize(); i++)
{
m_combo1.AddString(arr[0][i]);
m_listbox.AddString(arr[1][i]);
}