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

質問編集履歴

2

整理

2020/09/24 23:33

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,17 +1,11 @@
1
- 以下のようにCStringを読み書きしているとプログラム終了時にエラーになってしまいます。
1
+ 以下のようにstreamで読み書きしているとプログラム終了時にエラーになってしまいます。このエラーを出ないようにしたいのですが、よく分からず。
2
- このエラーを出ないようにしたいのですが、よく分からず。
3
2
 
4
- ※他の入出力方法を求めているわけではないです。
5
-
6
3
  ```c++
7
- CString w_str("文字");
4
+ CString w_str("文字");
8
5
  CString r_str;
9
- std::stringstream st;
6
+ stringstream st;
10
- std::iostream& io(st);
7
+ iostream io(st);
11
8
  int size = w_str.GetLength() * sizeof(TCHAR);
12
- io.write((const char*)&w_str, size);
9
+ io.write(w_str.GetString(), size);
13
- io.read((char*)&r_str, size);
10
+ io.read((const*)&r_str, size);
14
- ```
11
+ ```
15
-
16
- **エラー内容**
17
- ![イメージ説明](3d45769bc56c226f94f70b65a463951a.png)

1

コード整理

2020/09/24 23:33

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,32 +1,16 @@
1
- 以下のようにCStringをstringstreamに読み書きしているとプログラム終了時にエラーになってしまいます。
1
+ 以下のようにCStringを読み書きしているとプログラム終了時にエラーになってしまいます。
2
2
  このエラーを出ないようにしたいのですが、よく分からず。
3
- おそらく、i_base.readのr_strが原因だと思うのですが、
4
3
 
5
4
  ※他の入出力方法を求めているわけではないです。
6
5
 
7
6
  ```c++
8
- #include <atlstr.h>
9
- #include <sstream>
10
- #include <iostream>
11
-
12
- int main()
13
- {
14
- CString w_str("文字列");
7
+ CString w_str("文字列");
15
- CString r_str;
8
+ CString r_str;
9
+ std::stringstream st;
10
+ std::iostream& io(st);
16
- int size = w_str.GetLength() * sizeof(TCHAR);
11
+ int size = w_str.GetLength() * sizeof(TCHAR);
17
- r_str.GetBuffer(size);
18
-
19
- std::stringstream s;
20
- std::ostream& os(s);
21
- os.write((const char*)&w_str, size);
12
+ io.write((const char*)&w_str, size);
22
-
23
- std::istream& is(s);
24
- is.read((char*)&r_str, size);
13
+ io.read((char*)&r_str, size);
25
-
26
- r_str.ReleaseBuffer();
27
-
28
- return 0;
29
- }
30
14
  ```
31
15
 
32
16
  **エラー内容**