Reversed
Reversed

Reputation: 51

How to create a CString from an array of chars?

Need to log the content of buf using the LogMethod() below the problem is that LogMethos only accepts a "Const CString&"

char buf[1024];
strcpy(buf, cErrorMsg);

// need to pass to LogMethod "buf" how do i do that?
log.LogMethod(const CString &); 

Thans Rev

Reversed

Upvotes: 1

Views: 2167

Answers (3)

Ruddy
Ruddy

Reputation: 1754

log.LogMethod(CString(buf));

This will avoid the problem where the compiler won't automatically create the CString object using the appropriate constructor since the argument is a reference (It would have if the argument was a "plain" CString).

Upvotes: 1

avakar
avakar

Reputation: 32635

If you're talking about MFC CString, as far as I can tell, it should have a non-explicit constructor taking TCHAR const *. In other words, the following should work.

log.LogMethod(buf); 

If it doesn't, please post the error message.

Upvotes: 1

sdornan
sdornan

Reputation: 2835

CString cs;
cs = buf;

log.LogMethod(cs)

Upvotes: 0

Related Questions