1
我嘗試轉換的wstring爲const WCHAR *,但空終端不工作,我想到:wstring的爲const WCHAR *使用c_str()
是否有任何方法可以將wstring轉換爲const wchar *的方式,我正在嘗試?
我嘗試轉換的wstring爲const WCHAR *,但空終端不工作,我想到:wstring的爲const WCHAR *使用c_str()
是否有任何方法可以將wstring轉換爲const wchar *的方式,我正在嘗試?
works[5]
和doesntWork[5]
都會導致未定義的行爲。緩衝區僅在[4]
之間有效,而[5]
不在此範圍內。
const wchar_t *works = L"Test";
works[0] -> L'T'
works[1] -> L'e'
works[2] -> L's'
works[3] -> L't'
works[4] -> L'\0'
works[5] -> undefined behavior, the program is broken if it ever tries to access this
的可能重複[我要的std :: string轉換爲一個const WCHAR \ _t \ *](http://stackoverflow.com/questions/246806/i-want-to-convert-stdstring- into-a-const-wchar-t) – 101010
你有沒有試過const_cast? – Beed
@Beed,'c_str()'返回'const wchar_t *'。它存儲在一個'const wchar_t *'中。爲什麼'const_cast'會有幫助? – chris