求教CString类重载的+=运算符的有关问题
求教CString类重载的+=运算符的问题
m_strline+=nChar;
其中m_strline是一个CString类对象,nChar是一个ASCII码,这条语句报错“more than one operator match these operand”。请问是什么原因,应该如何修改?
------解决思路----------------------
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/dv_vclib/html/39569564-290e-4b6f-a829-2919556bee32.htm
Shared Visual C++ Classes Reference
CStringT::operator +
Example See Also Send Feedback
Concatenates two strings or a character and a string.
friend CStringT operator+(
const CStringT& str1,
const CStringT& str2
);
friend CStringT operator+(
const CStringT& str1,
PCXSTR psz2
);
friend CStringT operator+(
PCXSTR psz1
const CStringT& str2,
);
friend CStringT operator+(
char ch1
const CStringT& str2,
);
friend CStringT operator+(
const CStringT& str1,
char ch2
);
friend CStringT operator+(
const CStringT& str1,
wchar_t ch2
);
friend CStringT operator+(
wchar_t ch1
const CStringT& str2,
);
Parameters
ch1
An ANSI or Unicode character to concatenate with a string.
ch2
An ANSI or Unicode character to concatenate with a string.
str1
A CStringT to concatenate with a string or character.
str2
A CStringT to concatenate with a string or character.
psz1
A pointer to a null-terminated string to concatenate with a string or character.
psz2
A pointer to a string to concatenate with a string or character.
Remarks
There are seven overload forms of the CStringT::operator+ function. The first version concatenates two existing CStringT objects. The next two concatenate a CStringT object and a null-terminated string. The next two concatenate a CStringT object and an ANSI character. The last two concatenate a CStringT object and a Unicode character.
Note:
Although it is possible to create CStringT instances that contain embedded null characters, we recommend against it. Calling methods and operators on CStringT objects that contain embedded null characters can produce unintended results.
Example
Visual C++ Copy Code
// typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;
CAtlString s1(_T("dog ")), s2(_T(" awake")), s3; // Empty CAtlString objects
s1= _T("The ") + s1;
s3= s1 + _T('i');
s3= s3 + _T('s');
s3= s3 + s2;
ASSERT(s3 == _T("The dog is awake"));
Requirements
Header: cstringt.h
See Also
Concepts
CStringT Class
CStringT Members
Send feedback on this topic to Microsoft.
m_strline+=nChar;
其中m_strline是一个CString类对象,nChar是一个ASCII码,这条语句报错“more than one operator match these operand”。请问是什么原因,应该如何修改?
------解决思路----------------------
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/dv_vclib/html/39569564-290e-4b6f-a829-2919556bee32.htm
Shared Visual C++ Classes Reference
CStringT::operator +
Example See Also Send Feedback
Concatenates two strings or a character and a string.
friend CStringT operator+(
const CStringT& str1,
const CStringT& str2
);
friend CStringT operator+(
const CStringT& str1,
PCXSTR psz2
);
friend CStringT operator+(
PCXSTR psz1
const CStringT& str2,
);
friend CStringT operator+(
char ch1
const CStringT& str2,
);
friend CStringT operator+(
const CStringT& str1,
char ch2
);
friend CStringT operator+(
const CStringT& str1,
wchar_t ch2
);
friend CStringT operator+(
wchar_t ch1
const CStringT& str2,
);
Parameters
ch1
An ANSI or Unicode character to concatenate with a string.
ch2
An ANSI or Unicode character to concatenate with a string.
str1
A CStringT to concatenate with a string or character.
str2
A CStringT to concatenate with a string or character.
psz1
A pointer to a null-terminated string to concatenate with a string or character.
psz2
A pointer to a string to concatenate with a string or character.
Remarks
There are seven overload forms of the CStringT::operator+ function. The first version concatenates two existing CStringT objects. The next two concatenate a CStringT object and a null-terminated string. The next two concatenate a CStringT object and an ANSI character. The last two concatenate a CStringT object and a Unicode character.
Note:
Although it is possible to create CStringT instances that contain embedded null characters, we recommend against it. Calling methods and operators on CStringT objects that contain embedded null characters can produce unintended results.
Example
Visual C++ Copy Code
// typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;
CAtlString s1(_T("dog ")), s2(_T(" awake")), s3; // Empty CAtlString objects
s1= _T("The ") + s1;
s3= s1 + _T('i');
s3= s3 + _T('s');
s3= s3 + s2;
ASSERT(s3 == _T("The dog is awake"));
Requirements
Header: cstringt.h
See Also
Concepts
CStringT Class
CStringT Members
Send feedback on this topic to Microsoft.