CString value to char buffer[256] 
Author Message
 CString value to char buffer[256]

So being new to the MFC area I am use to doing my string algorithms with
strcpy and such.  How can I get a CString value in to a char buffer variable
such as....

CString cs1 = "test";
char buffer[256];

Thanks
James



Fri, 24 Oct 2003 11:30:39 GMT  
 CString value to char buffer[256]
strcpy( buffer, cs1 ) ;


Fri, 24 Oct 2003 11:35:46 GMT  
 CString value to char buffer[256]
Or ...
cs1.Format( "%s", buffer );

:-)

killem


Quote:
> So being new to the MFC area I am use to doing my string algorithms with
> strcpy and such.  How can I get a CString value in to a char buffer
variable
> such as....

> CString cs1 = "test";
> char buffer[256];

> Thanks
> James



Fri, 24 Oct 2003 11:45:04 GMT  
 CString value to char buffer[256]
I tried the obvious :) and got this as an error.

 error C2664: 'strcpy' : cannot convert parameter 2 from 'class CString' to
'const char *'

char chostname[INTERNET_MAX_HOST_NAME_LENGTH];
CString hn;

strcpy(chostname,hn);



Quote:
> strcpy( buffer, cs1 ) ;



Sat, 25 Oct 2003 01:12:34 GMT  
 CString value to char buffer[256]
I get the follow error as a result....

error C2664: 'void __cdecl CString::Format(const unsigned short *,...)' :
cannot convert parameter 1 from 'char [3]' to 'const unsigned short *'


Quote:
> Or ...
> cs1.Format( "%s", buffer );

> :-)

> killem



> > So being new to the MFC area I am use to doing my string algorithms with
> > strcpy and such.  How can I get a CString value in to a char buffer
> variable
> > such as....

> > CString cs1 = "test";
> > char buffer[256];

> > Thanks
> > James



Sat, 25 Oct 2003 01:14:00 GMT  
 CString value to char buffer[256]
are you in a UNICODE build?

roy fine


Quote:
> I get the follow error as a result....

> error C2664: 'void __cdecl CString::Format(const unsigned short *,...)' :
> cannot convert parameter 1 from 'char [3]' to 'const unsigned short *'



> > Or ...
> > cs1.Format( "%s", buffer );

> > :-)

> > killem



> > > So being new to the MFC area I am use to doing my string algorithms
with
> > > strcpy and such.  How can I get a CString value in to a char buffer
> > variable
> > > such as....

> > > CString cs1 = "test";
> > > char buffer[256];

> > > Thanks
> > > James



Sat, 25 Oct 2003 01:29:33 GMT  
 CString value to char buffer[256]
Then something else not obvious is the problem. I compiled and executed the
following successfuly:

char chostname[255];
CString hn="For James Shelby";
strcpy(chostname, hn);
puts(chostname);

I did that in a MFC console program and it worked.


Quote:
> I tried the obvious :) and got this as an error.

>  error C2664: 'strcpy' : cannot convert parameter 2 from 'class CString'
to
> 'const char *'

> char chostname[INTERNET_MAX_HOST_NAME_LENGTH];
> CString hn;

> strcpy(chostname,hn);



> > strcpy( buffer, cs1 ) ;



Sat, 25 Oct 2003 02:30:21 GMT  
 CString value to char buffer[256]
You must be in a Unicode build.  If you didn't mean to be doing a
Unicode build, switch to ASCII and retry; your code should work.  If
you really want to copy a Unicode CString object to a char array, see
the WideCharToMultibyte function.  Also, for easier conversion between
Unicode and ASCII, see TN059.
http://msdn.microsoft.com/library/devprods/vs6/visualc/vcmfc/_mfcnotes
_tn059.htm

Vic


Quote:
> I tried the obvious :) and got this as an error.

>  error C2664: 'strcpy' : cannot convert parameter 2 from 'class
CString' to
> 'const char *'

> char chostname[INTERNET_MAX_HOST_NAME_LENGTH];
> CString hn;

> strcpy(chostname,hn);



> > strcpy( buffer, cs1 ) ;



Sat, 25 Oct 2003 03:18:52 GMT  
 CString value to char buffer[256]
Hmm..note that this is also for the embedded Visual CE platform...I will try
without unicode...


Quote:
> You must be in a Unicode build.  If you didn't mean to be doing a
> Unicode build, switch to ASCII and retry; your code should work.  If
> you really want to copy a Unicode CString object to a char array, see
> the WideCharToMultibyte function.  Also, for easier conversion between
> Unicode and ASCII, see TN059.
> http://msdn.microsoft.com/library/devprods/vs6/visualc/vcmfc/_mfcnotes
> _tn059.htm

> Vic



> > I tried the obvious :) and got this as an error.

> >  error C2664: 'strcpy' : cannot convert parameter 2 from 'class
> CString' to
> > 'const char *'

> > char chostname[INTERNET_MAX_HOST_NAME_LENGTH];
> > CString hn;

> > strcpy(chostname,hn);



> > > strcpy( buffer, cs1 ) ;



Sat, 25 Oct 2003 09:56:15 GMT  
 CString value to char buffer[256]
Its the visual embedded version, how can I tell?

James



Quote:
> are you in a UNICODE build?

> roy fine



> > I get the follow error as a result....

> > error C2664: 'void __cdecl CString::Format(const unsigned short *,...)'
:
> > cannot convert parameter 1 from 'char [3]' to 'const unsigned short *'



> > > Or ...
> > > cs1.Format( "%s", buffer );

> > > :-)

> > > killem



> > > > So being new to the MFC area I am use to doing my string algorithms
> with
> > > > strcpy and such.  How can I get a CString value in to a char buffer
> > > variable
> > > > such as....

> > > > CString cs1 = "test";
> > > > char buffer[256];

> > > > Thanks
> > > > James



Sat, 25 Oct 2003 10:11:25 GMT  
 CString value to char buffer[256]
So I did a RTFM (Read The "Fine" Manual) and found that Windows CE 3.0 is
Unicode only...based upon the answer you gave here I should be able to get
where I need to be...

Thanks
James


Quote:
> You must be in a Unicode build.  If you didn't mean to be doing a
> Unicode build, switch to ASCII and retry; your code should work.  If
> you really want to copy a Unicode CString object to a char array, see
> the WideCharToMultibyte function.  Also, for easier conversion between
> Unicode and ASCII, see TN059.
> http://msdn.microsoft.com/library/devprods/vs6/visualc/vcmfc/_mfcnotes
> _tn059.htm

> Vic



> > I tried the obvious :) and got this as an error.

> >  error C2664: 'strcpy' : cannot convert parameter 2 from 'class
> CString' to
> > 'const char *'

> > char chostname[INTERNET_MAX_HOST_NAME_LENGTH];
> > CString hn;

> > strcpy(chostname,hn);



> > > strcpy( buffer, cs1 ) ;



Sun, 26 Oct 2003 14:46:17 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Any way to convert char (*) [256] to char * []?

2. CString to char buffer[40]

3. CString to Char and Char to CString

4. char[100] to CString and CString to char[100] again

5. BYTE buffer[256] -> VARIANT

6. how do i convert a CString to a char[value]

7. Assigning char * value to a CString object

8. CString with limit of 256

9. How2 use CString for more than 256 characters

10. Marshal::StringToHGlobalAnsi corrupts output after 256 chars

11. getchar and 256 char hangup

12. var type: (char (*)[256])

 

 
Powered by phpBB® Forum Software