-
July 4th, 2012, 03:44 AM
#1
Trouble with the CString class
Hi everyone,
I am trying to use the CString class to concatenate some string but i am getting a strange compiler error. The code is as follows:
void CTesterDlg::OnBnClickedButton1()
{
UpdateData(TRUE);
m_Output=m_Hostname+"and";
SetDlgItemText(IDC_EDIT2,m_Output);
}
Where m_Output and m_Hostname are CString variables.
The compiler error is this:
1>c:\documents and settings\administrator\my documents\visual studio 2005\projects\router monkey\router monkey\router monkeydlg.cpp(169) : error C2679: binary '+' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)
1> e:\visual studio 8\vc\atlmfc\include\atlsimpstr.h(666): could be 'ATL::CSimpleStringT<BaseType> ATL::CSimpleStringT<BaseType>:perator +(const ATL::CSimpleStringT<BaseType> &,const ATL::CSimpleStringT<BaseType> &)' [found using argument-dependent lookup]
Anyone know why this error is happening and how i can fix it ?
-
July 4th, 2012, 04:14 AM
#2
Re: Trouble with the CString class
I can't get from where the 'const char [2]' come from but that should work if you build for MBCS. Try this
Code:
m_Output=m_Hostname+_T("and");
instead
-
July 4th, 2012, 05:25 AM
#3
Re: Trouble with the CString class
Thank S_M_A that worked !
Another silly question. Why doesn't the newline operator work i am trying to output a string to the an edit box but the \n doesn't seem to work:
m_Output=_T("testing \n")+m_Hostname;
-
July 4th, 2012, 05:50 AM
#4
Re: Trouble with the CString class
I haven't done any windows programming for quite a long time now but if I don't remember wrong you use \r in an edit box. Also make sure it's a multi line enabled edit box.
-
July 4th, 2012, 06:10 AM
#5
Re: Trouble with the CString class
Beside the fact that your edit control must be multi-line (have ES_MULTILINE style set) you have to use "\r\n" (CRLF, "carriage return" and "line feed" / "new line") for line delimiter.
-
July 4th, 2012, 06:17 AM
#6
Re: Trouble with the CString class
Should have looked that up instead of relying on my bad memory...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|