有语法错误“error C2001: newline in constant”----一个MFC初学者的问题

时间:2021-07-19 22:59:16
void CMyView::OnPrevPane() 
{
// TODO: Add your command handler code here
CString sFilename(GetDocument()->GetPathName());
CString sTitle(GetDocument()->GetTitle());
int nTitle=atoi(sTitle);
int nFind;
if ((nTitle>1)&(nTitle<=3))
{
sTitle.Format("%d", nTitle-1 );
nFind = sFilename.ReverseFind('\\\');
if(nFind>0)
{
CString sNewFilename(sFilename.Left(nFind)+ "\\\" + sTitle+".txt" );
AfxGetApp()->OpenDocumentFile(sNewFilename);
}
}
else
AfxMessageBox("没有上一文件了");

}
在nFind = sFilename.ReverseFind('\\\');处报错:error C2001: newline in constant;error C2015:too many characters in constant
为什么呢?

6 个解决方案

#1


'\\\'改成'\\'

#2


'\\'

#3


if ((nTitle>1)&(nTitle<=3))
&的使用有错误吗?

#4


引用 3 楼 zxfengye 的回复:
if ((nTitle>1)&amp;(nTitle<=3))
&amp;的使用有错误吗?

&表示按位与,&&表示逻辑与,这里应该是用&&

#5


if ((nTitle>1)&(nTitle<=3))
-->
if ((nTitle>1)&&(nTitle<=3))
你这里是判断nTitle是在(1, 3]之间吧,大于1小于等于3

#6


谢谢!

#1


'\\\'改成'\\'

#2


'\\'

#3


if ((nTitle>1)&(nTitle<=3))
&的使用有错误吗?

#4


引用 3 楼 zxfengye 的回复:
if ((nTitle>1)&amp;(nTitle<=3))
&amp;的使用有错误吗?

&表示按位与,&&表示逻辑与,这里应该是用&&

#5


if ((nTitle>1)&(nTitle<=3))
-->
if ((nTitle>1)&&(nTitle<=3))
你这里是判断nTitle是在(1, 3]之间吧,大于1小于等于3

#6


谢谢!