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