Re: CString and cout in VC++ 2005

Tech-Archive recommends: Speed Up your PC by fixing your registry



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:

Hi

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
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • CString and cout in VC++ 2005
    ... I have created a win32 console app with MFC /ATL Support in VC++ 6 and ... What works in VC6 doesnt work the same in VC2005. ... CString str1; ...
    (microsoft.public.vc.mfc)
  • Re: CString and cout in VC++ 2005
    ... CString str1; ... I have created a win32 console app with MFC /ATL Support in VC++ 6 and ... What works in VC6 doesnt work the same in VC2005. ...
    (microsoft.public.vc.mfc)