strPath = CGlobal::m_BackupAddress;
strPath += strTime;
strPath = "C:\\Backup\\";
strPath += strTime;如上两段代码,第一段中CGlobal::m_BackupAddress也是CString型的,我单步到strPath = CGlobal::m_BackupAddress时 strPath在监视窗里面看到的内容是"C:\Backup",继续单步一步,加上strTime之后,strPath居然等于strTime了!第二段代码能够正常运行!!!
尝试了几次都不行,而且第一段中我还把strPath赋值给一个strTemp,然后让strTemp+= strTime,居然strTemp也等于strTime了!太诡异了!
strPath = CGlobal::m_BackupAddress;之后用了AfxMesssageBox(strPath)输出C:\Backup\"
strPath += strTime; AfxMessageBox(strPath) 输出"2012-8-28"
CGloabl
{
public:
static CString m_BackupAddress;
}这是我m_BackupAddress的定义,不会有问题吧?
strPath.Format(_T("%s%s"), CGlobal::m_BackupAddress, strTime);
AfxMessageBox(strPath);
静态变量赋值给一个普通变量只是暂时改变了普通变量的值,在下一次赋值时,因为存储
位置不同所以值被重新覆盖了。
class CTest
{
public:
static int a;
};
int CTest::a = 1;
void main()
{
int b(0),c(1);
b = CTest::a;
b += c;
cout<<b<<endl;
}
按照你这个说法的话,这段代码是不是应该输出1? 但是我看到输出的是2!!!
{
public:
static CString m_BackupAddress;
}
//
m_BackupAddress;在那里赋值?
我发现用::GetPrivateProfileString读出来的值,貌似不能进行一部分操作! 不知道是不是!!
LPCTSTR lpAppName, // points to section name
LPCTSTR lpKeyName, // points to key name
LPCTSTR lpDefault, // points to default string
LPTSTR lpReturnedString, // points to destination buffer
DWORD nSize, // size of destination buffer
LPCTSTR lpFileName // points to initialization filename
);
File: "C:\Program Files\Microsoft Visual Studio\VC98\Include\WINNT.H" 2 occurrences found on 2 lines
182: typedef LPCWSTR LPCTSTR;
196: typedef LPCSTR LPCTSTR;
File: "C:\Program Files\Microsoft Visual Studio\VC98\Include\WTYPES.H" 1 occurrences found on 1 lines
209: typedef /* [string] */ const CHAR __RPC_FAR *LPCSTR;
CString s1,s2;
s1 = "111";
s2 =strTemp+s1;这段代码最后为什么s2还是"111"?
个人估计是你用GetPrivateProfileString函数用的有问题,导致栈上的数据出错...
例如GetPrivateProfileString("Student","Name","DefaultName",SName.GetBuffer(MAX_LENGTH),MAX_LENGTH,"c:\\setting.ini");结果:SName = "jacky";这里需要注意点就是用完GetBuffer函数后一定要释放(用SName.ReleaseBuffer()函数),不然后面再用到SName的其他子函数就会失灵。