Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy string starter for 10 1

Status
Not open for further replies.

Frink

Programmer
Mar 16, 2001
798
0
0
GB
Hallo,

I'm having a bit of trouble with strings, namely converting between arrays of BYTEs and wstrings.
I have the following code:
Code:
BYTE Name[]="output.txt"
wstring filename = L"C:\Temp\"
What's the line of code to append Name to filename?
(so that filename = 'C:\Temp\output.txt')
I've tried lots of things, but just get incomprehensible error messages which stretch over three lines.
As you can probably tell I'm new to C++ and I can't say that I like it.
The code is inherited, and I'm not able to change any of the types involved.

Any help much appreciated,

- Frink
 
Frink,
To append
Code:
Name
to
Code:
filename
you have to convert name to unicode (wide string):

Code:
filename += _TCHAR(name);

I take it you want the result in the wstring?

Rob


 
I seriously doubt that casting BYTE to _TCHAR like so:
_TCHAR(name) will work.

_TCHARs depend on the build, if non-unicode then they're just ordinary chars.
Greetings,
Rick
 
Hallo,

I've managed to convert by BYTE array into a wchar_t array using mbstowcs, which I can then use in wstring member functions. It's pants, but will do for now.
If C++ is so complicated, how come so many people like it??

- Frink
 
As mentioned by Rick, TCHAR is dependent on if UNICODE is defined. However, I believe you can use MultiByteToWideChar and WideCharToMultiByte for your conversions.

MSDN provides a genric text example and I dont know if it would be of any use to you. See msdn for:

"A Saple Generic-Text Program" Search msdn for GenText.c

Matt
 
"If C++ is so complicated, how come so many people like it??"

Complicated yes, but very powerful!
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Call me old fashioned, but I'd rather have a language which was simple to write and the compiler sorted out all the hard stuff.

Of course, no such language exists, until I write Frink1, of course :)

- Frink
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top