回答編集履歴
1
std::stringのまま動作するコードを追記
answer
CHANGED
@@ -13,4 +13,21 @@
|
|
13
13
|
{
|
14
14
|
delete pStream;
|
15
15
|
}
|
16
|
+
```
|
17
|
+
|
18
|
+
(追記)
|
19
|
+
解決済みですが一応…
|
20
|
+
filenameがstd::stringのままで動くもの。
|
21
|
+
```C++
|
22
|
+
std::ostream* pStream = new std::ofstream(filename);
|
23
|
+
if (pStream->fail())
|
24
|
+
{
|
25
|
+
delete pStream;
|
26
|
+
pStream = &std::cout;
|
27
|
+
}
|
28
|
+
*pStream << "hogehoge" << std::endl;
|
29
|
+
if (pStream != &std::cout)
|
30
|
+
{
|
31
|
+
delete pStream;
|
32
|
+
}
|
16
33
|
```
|