Why Don't You Use String Views Instead of Passing Std:Wstring by Const&

Win32 dev says “no” to string_view; comment section explodes

TLDR: A Windows coder says don’t swap real strings for string “views” when calling system APIs that require a zero at the end, or you risk sneaky bugs. Commenters split between blaming C’s ancient design, preaching DIY modern fixes, and venting cross-language pain—highlighting how old APIs still shape today’s code.

A Windows C++ programmer drew a line in the sand: when calling old-school Win32 system functions that expect null-terminated text, he’s sticking with passing full wide strings by reference—not trendy “string views.” Why? Because a view doesn’t guarantee that extra invisible “end of string” marker, and that mismatch can turn into mysterious bugs. His tip: call c_str() so any “modernization” to a view fails at compile time instead of exploding at runtime. The internet had thoughts.

The most fiery take? One commenter torched C’s design as “the worst decision ever,” blaming null-terminated strings for decades of bugs and security mess. Another clapped back that the blog’s tone screams “innovation bad,” insisting you can write a custom view with c_str() and keep things modern. Meanwhile, cross-language devs piled on with “this is pain” stories—if your language doesn’t end strings with a zero, you’re copying and patching just to talk to Windows. An embedded engineer flexed a war story: 64KB RAM, no dynamic memory, fixed-size strings that are both length-aware and zero-terminated—pragmatism over purity.

The vibe? Team Safety versus Team New Hotness. Memes flew about “Pascal strings” (length-first) and jokes about “old man yells at cloud” coding. But beneath the snark is a real point: when your code speaks to ancient-but-critical system APIs, fancy shortcuts can cut deep. Choose your string wisely—and maybe your battles, too.

Key Points

  • Win32 APIs commonly expect null-terminated wide strings (PCWSTR), a const wchar_t* with a trailing null.
  • std::wstring::data() provides a pointer to a null-terminated buffer suitable for PCWSTR.
  • std::wstring_view::data() does not guarantee null-termination, making it unsafe for Win32 APIs that require it.
  • Using c_str() on std::wstring is recommended to enforce null-terminated input and catch incorrect refactors at compile time.
  • If an API needs to write into the buffer, use data() due to its const and non-const overloads.

Hottest takes

"The zero-terminated string is by far C’s worst design decision" — delta_p_delta_x
"The more strident someone is… the more wrong he is" — quotemstr
"Painful to use from other languages… require taking a copy" — Panzerschrek
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.