两个函数之间的数组调用以及函数调用
void CWorkView::Onsave()
{
// TODO: Add your control notification handler code here
extern str;
extern i;
CString pstn[1000];
int j=0;
pstn[j]=str[i];
j++;
m_edit=" ";
}
void CWorkView::Oncatch()
{
// TODO: Add your control notification handler code here
CString str[1000];
CString temp;
int i=0;
char*pszFileName="C:\\a.txt";
CStdioFile a;
CFileException fileException;
if(a.Open(pszFileName,CFile::modeReadWrite),&fileException)
{
a.SeekToBegin();
do{
a.ReadString(str[i]);
temp.Format("%3d",str[i]);
m_edit=temp;
CWorkView::Onsave();
UpdateData(false);
i++;
}while(str[i-1]!="%");
//读出a文件中的信息,并显示;
}
else
{
TRACE("Can't open file %s,error=%u\n",pszFileName,fileException.m_cause);
}
a.Close();
}
错误代码:error C2109: subscript requires array or pointer type
执行 cl.exe 时出错.
onsave()函数调用oncatch()的str[]数组时出错!!
请高手赐教~~~~
[解决办法]
我宁愿用类的静态变量来解决,也不愿意看到extern这处关键字
你试试把与str[]相关的,转换成类静态变量试试
CString str[10]
换成在类声明里的 static CString str[10]
[解决办法]
::Onsave(CString str[],...)
[解决办法]
楼上的解决办法很好,不过少了变量i。应该是这样:
void CWorkView::Onsave(int i, CString* str)
{
// TODO: Add your control notification handler code here
// extern这两句删除不要
Onsave(i, str);
// CWorkView定义
class CWorkView
{
//以下是增加的部分
private:
int m_Count;//初始化时要归零,在CWorkView()中
CString m_str[1000];
CString m_pstn[1000];
};
// CWorkView实现
void CWorkView::Onsave(int Index)
{
pstn[m_Count++]=m_str[Index];
m_edit=" ";
}
void CWorkView::Oncatch()
{
// TODO: Add your control notification handler code here
CString temp;//这里temp是做什么用的?
int i=0;
char* pszFileName="C:\\a.txt";
CStdioFile a;
CFileException fileException;
if(a.Open(pszFileName, CFile::modeReadWrite), &fileException)
{
a.SeekToBegin();
do
{
a.ReadString(m_str[i]);
temp.Format("%3d", m_str[i]);
m_edit = temp;
Onsave(i++);
UpdateData(false);
} while(m_str[i-1] != "%");
}
else
{
TRACE(_T("Can't open file %s,error=%u\n"), pszFileName, fileException.m_cause);
}
a.Close();
}