回答編集履歴

1

追記

2020/06/28 00:23

投稿

episteme
episteme

スコア16612

test CHANGED
@@ -125,3 +125,151 @@
125
125
  }
126
126
 
127
127
  ```
128
+
129
+ [追記] "きろく"の直後から二度目の"きろく"の直前までを applog.txt に書き込むサンプル
130
+
131
+ ```C++
132
+
133
+ #include <DxLib.h>
134
+
135
+ #include <string>
136
+
137
+ #include <deque>
138
+
139
+ #include <vector>
140
+
141
+ #include <fstream>
142
+
143
+
144
+
145
+ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
146
+
147
+
148
+
149
+ std::deque<std::string> messages;
150
+
151
+ std::vector<std::string> log;
152
+
153
+ bool logging = false;
154
+
155
+
156
+
157
+ int InputHandle;
158
+
159
+
160
+
161
+ SetGraphMode(700, 780, 32);
162
+
163
+ ChangeWindowMode(TRUE);
164
+
165
+ if (DxLib_Init() == -1) return -1;
166
+
167
+ SetDrawScreen(DX_SCREEN_BACK);
168
+
169
+ SetFontSize(64);
170
+
171
+
172
+
173
+ InputHandle = MakeKeyInput(50, FALSE, FALSE, FALSE);
174
+
175
+ SetActiveKeyInput(InputHandle);
176
+
177
+
178
+
179
+ while (!ProcessMessage()) {
180
+
181
+ ClearDrawScreen();
182
+
183
+
184
+
185
+ if (CheckKeyInput(InputHandle) != 0) {
186
+
187
+ char buffer[256];
188
+
189
+ GetKeyInputString(buffer, InputHandle);
190
+
191
+ std::string input = buffer;
192
+
193
+ DrawString(0, 0, input.c_str(), GetColor(255, 255, 255));
194
+
195
+ if ( input == "きろく" ) {
196
+
197
+ if ( !logging ) { // 記録開始
198
+
199
+ log.clear();
200
+
201
+ logging = true;
202
+
203
+ } else { // 記録終了
204
+
205
+ std::ofstream stream("applog.txt");
206
+
207
+ for ( std::string line : log ) {
208
+
209
+ stream << line << std::endl;
210
+
211
+ }
212
+
213
+ logging = false;
214
+
215
+ }
216
+
217
+ } else {
218
+
219
+ if ( logging ) {
220
+
221
+ log.push_back(input);
222
+
223
+ }
224
+
225
+ messages.push_back(input);
226
+
227
+ }
228
+
229
+ while ( messages.size() > 5 ) {
230
+
231
+ messages.pop_front();
232
+
233
+ }
234
+
235
+ SetActiveKeyInput(InputHandle);
236
+
237
+ SetKeyInputString("", InputHandle);
238
+
239
+ }
240
+
241
+
242
+
243
+ DrawKeyInputModeString(640, 480);
244
+
245
+ int height = 100;
246
+
247
+ for ( std::string message : messages ) {
248
+
249
+ DrawString(100, height, message.c_str(), GetColor(200, 200, 255));
250
+
251
+ height += 60;
252
+
253
+ }
254
+
255
+ DrawKeyInputString(0, 0, InputHandle);
256
+
257
+
258
+
259
+ ScreenFlip();
260
+
261
+ }
262
+
263
+
264
+
265
+ DeleteKeyInput(InputHandle);
266
+
267
+ DxLib_End();
268
+
269
+
270
+
271
+ return 0;
272
+
273
+ }
274
+
275
+ ```