質問編集履歴
5
スペース→NULL
test
CHANGED
File without changes
|
test
CHANGED
@@ -80,7 +80,7 @@
|
|
80
80
|
|
81
81
|
# 試したこと3
|
82
82
|
|
83
|
-
WideCharToMultiByte を使用する方法として、以下の記事を参考にして作成しましたが、16バイト目に無駄な
|
83
|
+
WideCharToMultiByte を使用する方法として、以下の記事を参考にして作成しましたが、16バイト目に無駄なNULL(`0x00`)が含まれていました。
|
84
84
|
|
85
85
|
[http://nekko1119.hatenablog.com/entry/2017/01/02/054629](http://nekko1119.hatenablog.com/entry/2017/01/02/054629)
|
86
86
|
|
4
見やすくした
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
# 試したこと
|
7
|
+
# 試したこと1
|
8
8
|
|
9
|
-
|
9
|
+
このプログラムの場合0バイトのout.txtが作成されました。
|
10
10
|
|
11
11
|
```cpp
|
12
12
|
|
@@ -32,7 +32,9 @@
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
+
# 試したこと2
|
36
|
+
|
35
|
-
|
37
|
+
このプログラムで問題なく出力できましたが警告が出ています。警告をなくしたいです。
|
36
38
|
|
37
39
|
|
38
40
|
|
@@ -76,9 +78,9 @@
|
|
76
78
|
|
77
79
|
|
78
80
|
|
79
|
-
|
81
|
+
# 試したこと3
|
80
82
|
|
81
|
-
以下の記事を参考にして作成しましたが、16バイト目に無駄なスペース(`0x00`)が含まれていました
|
83
|
+
WideCharToMultiByte を使用する方法として、以下の記事を参考にして作成しましたが、16バイト目に無駄なスペース(`0x00`)が含まれていました。
|
82
84
|
|
83
85
|
[http://nekko1119.hatenablog.com/entry/2017/01/02/054629](http://nekko1119.hatenablog.com/entry/2017/01/02/054629)
|
84
86
|
|
3
情報追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -76,6 +76,74 @@
|
|
76
76
|
|
77
77
|
|
78
78
|
|
79
|
+
- WideCharToMultiByte を使用する方法
|
80
|
+
|
81
|
+
以下の記事を参考にして作成しましたが、16バイト目に無駄なスペース(`0x00`)が含まれていました.
|
82
|
+
|
83
|
+
[http://nekko1119.hatenablog.com/entry/2017/01/02/054629](http://nekko1119.hatenablog.com/entry/2017/01/02/054629)
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
![](628bef731d3f2252b2804a6d8b8bcc40.png)
|
88
|
+
|
89
|
+
※out.txtがプログラムで作成したテキストファイル。out2.txtがテキストエディタを使いUTF-8(BOMなし)で「あいうえお」という文字列を書き込んだファイル。
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
```cpp
|
94
|
+
|
95
|
+
#include <Windows.h>
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
#include <iostream>
|
100
|
+
|
101
|
+
#include <vector>
|
102
|
+
|
103
|
+
#include <string>
|
104
|
+
|
105
|
+
#include <fstream>
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
std::string wide_to_utf8_winapi(std::wstring const& src)
|
110
|
+
|
111
|
+
{
|
112
|
+
|
113
|
+
auto const dest_size = ::WideCharToMultiByte(CP_UTF8, 0U, src.data(), -1, nullptr, 0, nullptr, nullptr);
|
114
|
+
|
115
|
+
std::vector<char> dest(dest_size, '\0');
|
116
|
+
|
117
|
+
if (::WideCharToMultiByte(CP_UTF8, 0U, src.data(), -1, dest.data(), dest.size(), nullptr, nullptr) == 0) {
|
118
|
+
|
119
|
+
throw std::system_error{ static_cast<int>(::GetLastError()), std::system_category() };
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
return std::string(dest.begin(), dest.end());
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
int main() {
|
130
|
+
|
131
|
+
std::ofstream ofs("out.txt");
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
ofs << wide_to_utf8_winapi(L"あいうえお") << std::endl;
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
ofs.close();
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
|
146
|
+
|
79
147
|
# 環境
|
80
148
|
|
81
149
|
|||
|
2
情報追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -33,6 +33,12 @@
|
|
33
33
|
|
34
34
|
|
35
35
|
- このプログラムで問題なく出力できましたが警告が出ています。警告をなくしたいです。
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
また、`#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING`または
|
40
|
+
|
41
|
+
`#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS`すると警告は出ませんができれば他の方法で解決したいです。
|
36
42
|
|
37
43
|
```cpp
|
38
44
|
|
1
タグを追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|