Until this weekend, my last C++ program (more like a hello world “application”), dated from a few years ago. This weekend, I needed to write a small utility, that had to be very lightweight and fast. So I thought, why not try to write it C++? I must say, it was a bit of a challenge being a C# .NET programmer, but I succeeded. The biggest challenge though, turned out to be understanding strings in Visual C++.

As a C# programmer – used to just simply using the “String” class whenever text is involved – I was utterly confused to find many different constructs for strings in (Visual) C++. LPTSTR, LPCSTR, CString, TCHAR[], std:string… just to name a few. String types seem to live on different islands and in villages. There is an Unicode island, an ANSI island. On both islands there are “standard” and Microsoft villages.

It is very difficult to get a clear overview of Visual C++ string landscape, even by Googling. What I found where mainly forum threads with confusing answers, and MSDN articles shedding light only on Microsoft variants like LPTSTR.
But, I found a lighthouse, a guide that clearly explains the why and what of Visual C++ strings:

Unraveling Strings in Visual C++.

I hope this will help other .NET programmers who found themselves lost in a sting of C++ islands.

Leave a Reply





Human Verification