回答編集履歴
1
std::stringのまま動作するコードを追記
test
CHANGED
@@ -29,3 +29,37 @@
|
|
29
29
|
}
|
30
30
|
|
31
31
|
```
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
(追記)
|
36
|
+
|
37
|
+
解決済みですが一応…
|
38
|
+
|
39
|
+
filenameがstd::stringのままで動くもの。
|
40
|
+
|
41
|
+
```C++
|
42
|
+
|
43
|
+
std::ostream* pStream = new std::ofstream(filename);
|
44
|
+
|
45
|
+
if (pStream->fail())
|
46
|
+
|
47
|
+
{
|
48
|
+
|
49
|
+
delete pStream;
|
50
|
+
|
51
|
+
pStream = &std::cout;
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
*pStream << "hogehoge" << std::endl;
|
56
|
+
|
57
|
+
if (pStream != &std::cout)
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
delete pStream;
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
```
|