VS2013 MFC运行时提示出错 5
如题这是一部分代码f1.Open(_T("F:\\test.txt"),CFile::modeCreate|CFile::modeNoTruncate|CFile::mo...
如题
这是一部分代码
f1.Open(_T("F:\\test.txt"), CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite);
f1.ReadString(str);
if (str == "0"){
CString s = _T("O"), s1;
SetDlgItemText(IDC_EDIT2, s);
a = 0;
s1.Format(_T("%d"), a);
f2.Open(_T("F:\\1.txt"), CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite);
f2.Write(s1, s1.GetLength());
}
else{
CString s = _T("X"), s1;
SetDlgItemText(IDC_EDIT2, s);
a = 1;
s1.Format(_T("%d"), a);
f2.Open(_T("F:\\1.txt"), CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite);
f2.Write(s1, s1.GetLength());
}
错误提示
Program: ...ers\Administrator.QH-20140605UGYO\Desktop\OOXX\Debug\OOXX.exe
File: f:\dd\vctools\crt\crtw32\stdio\fgets.c
Line: 57
Expression: ( str != NULL )
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts. 展开
这是一部分代码
f1.Open(_T("F:\\test.txt"), CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite);
f1.ReadString(str);
if (str == "0"){
CString s = _T("O"), s1;
SetDlgItemText(IDC_EDIT2, s);
a = 0;
s1.Format(_T("%d"), a);
f2.Open(_T("F:\\1.txt"), CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite);
f2.Write(s1, s1.GetLength());
}
else{
CString s = _T("X"), s1;
SetDlgItemText(IDC_EDIT2, s);
a = 1;
s1.Format(_T("%d"), a);
f2.Open(_T("F:\\1.txt"), CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite);
f2.Write(s1, s1.GetLength());
}
错误提示
Program: ...ers\Administrator.QH-20140605UGYO\Desktop\OOXX\Debug\OOXX.exe
File: f:\dd\vctools\crt\crtw32\stdio\fgets.c
Line: 57
Expression: ( str != NULL )
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts. 展开
展开全部
判断一下 f1.Open 成功了没有
更多追问追答
追问
成功了的
追答
_TSCHAR * __cdecl _fgetts (
_TSCHAR *string,
int count,
FILE *str
)
{
REG1 FILE *stream;
REG2 _TSCHAR *pointer = string;
_TSCHAR *retval = string;
int ch;
_VALIDATE_RETURN(( string != NULL ) || ( count == 0 ), EINVAL, NULL);
_VALIDATE_RETURN(( count >= 0 ), EINVAL, NULL);
_VALIDATE_RETURN(( str != NULL ), EINVAL, NULL); //这是第57行
从你的描述上看应该是str为空导致的问题.
可以在出现错误提示的时候调试一下或者直接在ReadString函数上步入,看看各个参数值是否正确.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询