开发者

how many types of strings in visual c++

How many types of string classes a开发者_开发百科re there in visual c++. I got confused when i was going through the msdn center.

I found this type under the namespace system http://msdn.microsoft.com/en-us/library/system.string(v=VS.71).aspx

and then in the headers section, i found the string header definitions. This seemed different from the above. One thing i noticed, this one comes under the STL. (pls see the comment for the link, i cant post two links in the same post)

which one is normally used? I'm finding a hard time getting around with the different string classes

Thanks in advance :)


Different libraries come with different string types:

In plain old C you would use char*, the C++ standard library provides std::string which is widely used in C++ development. (string is defined as typedef basic_string<char> string;)

Microsoft created the MFC CString class which is (was?) used in MFC style programming, Qt has its QString which is used in Qt programs. What you're mentioning with System.String is a .net string class which can only be used in Managed code (with .net).

I'd suggest to stick with std::string (#include <string>) if you're new to C++. It's standard and platform independent.


String types in common use in Microsoft code are char*, wchar_t*, LPSTR, LPTSTR, LPWSTR, LPCSTR, LPCTSTR, LPCWSTR, BSTR, OLESTR, UNICODE_STRING, String, string, wstring, _bstr_t, CString

The last 5 are classes. You pick the one that gives you the least conversion headaches, depending on what API you need to use:

  • std::string and wstring, standard C++ library
  • System::String, the string type for managed code
  • _bstr_t, wrapper for a BSTR, used in COM automation
  • CString, string type for the ATL and MFC libraries.

You're likely to encounter additional string types when you work with other APIs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜