Re: CString and cout in VC++ 2005
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Wed, 26 Jul 2006 23:48:04 -0400
First, you should never be using undecorated quoted strings in any program unless you are
absolutely certain beyond any shadow of a doubt that you will never, ever have to use
Unicode. Since by default VS.NET 2005 creates Unicode apps, you are going to get all
sorts of weird artifacts.
CString str1(_T("hello"));
Next, do NOT use GetBuffer unless you have a corresponding ReleaseBuffer (which you don't
show here) and in any case, this is a lousy way to get the contents of the buffer.
cout << (LPCTSTR)str1 << endl;
should be a better approach (since I wouldn't use cout on a bet for any purpose, I have
little familiarity with all of its subtleties). You should not be using GetBuffer for
such a trivial purpose as casting (it is an expensive operation compared to the (LPCTSTR)
cast)
The code should then work in VS.NET 2005 because it doesn't use platform and
character-code-specific mechanisms.
joe
On Wed, 26 Jul 2006 15:41:53 -0500, victor <victor75040@xxxxxxxxx> wrote:
HiJoseph M. Newcomer [MVP]
I have created a win32 console app with MFC /ATL Support in VC++ 6 and
VC++ 2005. What works in VC6 doesnt work the same in VC2005. Here is
what I mean:
In VC6:
CString str1("hello");
cout<<str1.GetBuffer(0)<<endl;
This will output the string str1 to the console window - No Problem
here.
In VC2005:
CString str1("hello");
cout<<str1.GetBuffer(0)<<endl;
The output is not "hello" but a memory location in hex. I know that
cout is working because something like :
cout<<"test"<<endl;
works fine.
I cannot find any specific information why this is happening in
VC2005. Any suggestions or solutions?
Thanks in advance for any help you can provide.
Victor
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: CString and cout in VC++ 2005
- From: Mihai N.
- Re: CString and cout in VC++ 2005
- References:
- CString and cout in VC++ 2005
- From: victor
- CString and cout in VC++ 2005
- Prev by Date: Re: How to prevent "Not Responding" on lengthy operations
- Next by Date: Re: Going From MFC to .NET
- Previous by thread: Re: CString and cout in VC++ 2005
- Next by thread: Re: CString and cout in VC++ 2005
- Index(es):
Relevant Pages
|