Horizon Posted October 23 Share Posted October 23 A common question that is often asked is whether C++ STL string objects (like std::string/wstring) or string views (e.g. std::wstring_view) should be passed as string parameters at Windows C-interface API boundaries. The following articles tries to shed some light on this subject, answering that question: Passing C++ STL Strings vs. String Views as Input Parameters at the Windows C API Boundary by Giovanni Dicanio From the article: Passing STL std::[w]string objects at Win32 API boundaries is common for C++ code that calls into Win32 C-interface APIs. When is it safe to pass *string views* instead? (...) the code will work fine. In fact, the wstring::c_str() method is guaranteed to return a null-terminated C-style string pointer. On the other hand, if you pass a string view like std::wstring_view in that context, you’ll likely get some subtle bugs! Try experimenting with the above API and something like “Connie is learning C++” and string views! View the full article Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.