# IStreamOut

本クラスは `namespace TWE` 内に定義されています。

出力ストリームの基底クラスで、以下のメソッドが定義されており、１バイトの出力、改行文字など特殊クラスを受け付けるためのメソッドが定義されています。

```cpp
virtual inline IStreamOut& operator ()(char_t c) = 0
virtual inline IStreamOut& write_w(wchar_t c)
```

`operator ()` は`char_t`型の１文字を出力するための仮想関数です。`write_w()`は`wchar_t`型の出力に対応します。

ストリームへの出力は`<<`演算子を用います。最終的には上記の出力用の関数が呼び出されます。

以下の例はITermクラスでの実装例です。

```cpp
class ITerm : public TWE::IStreamOut {
  // ... 各種定義
  
  ITerm& write(char_t c) {
    // ... １バイト入力を受け付ける処理
  }
  
  // StreamOut::operator () の実装
  TWE::IStreamOut& operator ()(char_t c) {
    write(c);
    return *this;
  }
};
```

## operator <<

```
inline IStreamOut& operator << (char_t c)
inline IStreamOut& operator << (wchar_t c)
inline IStreamOut& operator << (IStreamSpecial& sc)
```

operator << の右オペランドとして以下の型に対応します。

| 右オペランドの型          | 解説                           |
| ----------------- | ---------------------------- |
| `char_t`          | １バイト出力する                     |
| `const char *`    | 文字列を出力する                     |
| `wchar_t`         | ワイド文字を出力する（派生クラスで対応がある場合）    |
| `IStreamSpecial&` | 特殊文字列を出力する                   |
| `printfmt`        | printf()に相当する出力を行う           |
| `const int`       | printf("%d", *n*)に相当する出力を行う  |
| `double`          | printf("%.3%, *n*)に相当する出力を行う |

{% hint style="info" %}
曖昧性の解決のため、派生クラスで明示的なオーバーライドが必要になる場合があります。

```cpp
inline ITerm& operator << (ITerm& t, char_t c)
   { *static_cast<TWE::IStreamOut*>(&t) << c; return t; } 
```

{% endhint %}

## IStreamSpecial

特殊な文字列などを指定するためのオブジェクトを定義するための基底クラスです。

```cpp
class IStreamSpecial {
	public:
		virtual inline IStreamOut& operator ()(IStreamOut& of) = 0;
};
```

派生クラスとして CR LF (0x0d 0x0a) を出力する IStream\_endl が定義されています。

```cpp
class IStream_endl : public IStreamSpecial {
  inline IStreamOut& operator ()(IStreamOut& of) { 
    // ... CR LF の出力
    of ('\r');
    of ('\n');
  }
};

IStream_endl crlf;
```

オブジェクト`crlf`は以下のように使用します。

```cpp
the_screen << "Hello World!" << crlf;
```

##


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mwm5.twelite.info/1.0-2/references/basics/twe/untitled.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
