teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コード追記

2020/09/24 11:27

投稿

SHOMI
SHOMI

スコア4079

answer CHANGED
@@ -23,4 +23,29 @@
23
23
 
24
24
  return 0;
25
25
  }
26
+ ```
27
+
28
+ ---
29
+ `文字セット`の設定がUNICODE時に`stringstream`が文字化けしていてもいいなら以下でも通りますが…
30
+ ```C++
31
+ #include <atlstr.h>
32
+ #include <sstream>
33
+ #include <iostream>
34
+
35
+ int main()
36
+ {
37
+ CString w_str("文字列");
38
+ CString r_str;
39
+ int size = (w_str.GetLength() + 1) * sizeof(TCHAR);
40
+
41
+ std::stringstream s;
42
+ std::ostream& os(s);
43
+ os.write((const char*)w_str.GetString(), size);
44
+
45
+ std::istream& is(s);
46
+ is.read((char*)r_str.GetBuffer(size), size);
47
+ r_str.ReleaseBuffer();
48
+
49
+ return 0;
50
+ }
26
51
  ```