質問編集履歴
4
説明文の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -124,23 +124,23 @@
|
|
124
124
|
|
125
125
|
|
126
126
|
|
127
|
-
|
127
|
+
ユーザーが1と入力したら
|
128
|
-
|
128
|
+
|
129
|
-
Ace
|
129
|
+
Ace Spade
|
130
|
-
|
130
|
+
|
131
|
-
と
|
131
|
+
と表示されるんですが、
|
132
|
-
|
133
|
-
|
134
|
-
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
-
|
135
|
+
ユーザーが10と入力しても、1以外の数字を入力しても
|
136
|
-
|
136
|
+
|
137
|
-
|
137
|
+
Ace Spade
|
138
|
-
|
138
|
+
|
139
|
-
と
|
139
|
+
と表示されます
|
140
|
-
|
141
|
-
|
142
|
-
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
-
下記のコードを
|
143
|
+
下記のコードのどこを変更すれば良いでしょうか?
|
144
144
|
|
145
145
|
|
146
146
|
|
3
コードを進展させました
test
CHANGED
File without changes
|
test
CHANGED
@@ -246,27 +246,11 @@
|
|
246
246
|
|
247
247
|
|
248
248
|
|
249
|
-
struct Inve {
|
250
|
-
|
251
|
-
|
249
|
+
int main() {
|
252
250
|
|
253
251
|
char buffer[LINE];
|
254
252
|
|
255
|
-
|
253
|
+
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
int main() {
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
Inve record;
|
264
|
-
|
265
|
-
int num2;
|
266
|
-
|
267
|
-
//char buffer[LINE];
|
268
|
-
|
269
|
-
|
270
254
|
|
271
255
|
fstream myFile;
|
272
256
|
|
@@ -306,8 +290,6 @@
|
|
306
290
|
|
307
291
|
|
308
292
|
|
309
|
-
|
310
|
-
|
311
293
|
fstream myFile2;
|
312
294
|
|
313
295
|
myFile2.open("lab.txt");
|
@@ -316,7 +298,9 @@
|
|
316
298
|
|
317
299
|
cout << "Enter a number: ";
|
318
300
|
|
301
|
+
int num;
|
302
|
+
|
319
|
-
cin >> num
|
303
|
+
cin >> num;
|
320
304
|
|
321
305
|
|
322
306
|
|
@@ -324,21 +308,29 @@
|
|
324
308
|
|
325
309
|
|
326
310
|
|
311
|
+
for(int i = 0; i < LINE - 1; i++) {
|
312
|
+
|
313
|
+
myFile2.clear();
|
314
|
+
|
327
|
-
myFile2.seekg(
|
315
|
+
myFile2.seekg(0, ios::beg);
|
328
|
-
|
329
|
-
|
316
|
+
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
317
|
+
|
334
|
-
|
318
|
+
|
335
|
-
|
319
|
+
while(getline(myFile2, str)) {
|
320
|
+
|
336
|
-
|
321
|
+
myFile2 >> num;
|
322
|
+
|
337
|
-
|
323
|
+
}
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
cout << str;
|
328
|
+
|
329
|
+
|
338
330
|
|
339
331
|
myFile2.close();
|
340
332
|
|
341
|
-
|
333
|
+
|
342
334
|
|
343
335
|
system("pwd");
|
344
336
|
|
@@ -348,6 +340,4 @@
|
|
348
340
|
|
349
341
|
}
|
350
342
|
|
351
|
-
|
352
|
-
|
353
343
|
```
|
2
getlin()を使いました
test
CHANGED
File without changes
|
test
CHANGED
@@ -246,124 +246,108 @@
|
|
246
246
|
|
247
247
|
|
248
248
|
|
249
|
+
struct Inve {
|
250
|
+
|
251
|
+
int num2;
|
252
|
+
|
253
|
+
char buffer[LINE];
|
254
|
+
|
255
|
+
};
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
int main() {
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
Inve record;
|
264
|
+
|
265
|
+
int num2;
|
266
|
+
|
249
|
-
|
267
|
+
//char buffer[LINE];
|
268
|
+
|
269
|
+
|
270
|
+
|
250
|
-
|
271
|
+
fstream myFile;
|
272
|
+
|
251
|
-
myFile
|
273
|
+
myFile.open("lab.txt");
|
274
|
+
|
275
|
+
|
276
|
+
|
252
|
-
|
277
|
+
Card deck[13][4];
|
278
|
+
|
253
|
-
for (int i = 0; i <
|
279
|
+
for ( int i = 0; i < 13; ++i ) {
|
254
|
-
|
280
|
+
|
255
|
-
|
281
|
+
for ( int j = 0; j < 4; ++j ) {
|
282
|
+
|
256
|
-
|
283
|
+
deck[i][j] = Card(i+1,Card::Suit(j));
|
284
|
+
|
257
|
-
}
|
285
|
+
}
|
286
|
+
|
258
|
-
|
287
|
+
}
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
for ( auto& row : deck ) {
|
292
|
+
|
293
|
+
for ( auto& card : row ) {
|
294
|
+
|
295
|
+
cout << setw(16) << card.description();
|
296
|
+
|
297
|
+
myFile << setw(16) << card.description();
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
myFile.close();
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
|
259
|
-
re
|
311
|
+
fstream myFile2;
|
312
|
+
|
313
|
+
myFile2.open("lab.txt");
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
cout << "Enter a number: ";
|
318
|
+
|
319
|
+
cin >> num2;
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
string str;
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
myFile2.seekg(num2 * sizeof(record), ios::beg);
|
328
|
+
|
329
|
+
myFile2.read(reinterpret_cast<char *>(&record), sizeof(record));
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
cin.ignore();
|
334
|
+
|
335
|
+
cin.getline(record.num2, LINE);
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
myFile2.close();
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
system("pwd");
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
return 0;
|
260
348
|
|
261
349
|
}
|
262
350
|
|
263
351
|
|
264
352
|
|
265
|
-
struct Inve {
|
266
|
-
|
267
|
-
int num2;
|
268
|
-
|
269
|
-
char buffer[LINE];
|
270
|
-
|
271
|
-
};
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
int main() {
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
Inve record;
|
280
|
-
|
281
|
-
int num2;
|
282
|
-
|
283
|
-
//char buffer[LINE];
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
fstream myFile;
|
288
|
-
|
289
|
-
myFile.open("lab.txt");
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
Card deck[13][4];
|
294
|
-
|
295
|
-
for ( int i = 0; i < 13; ++i ) {
|
296
|
-
|
297
|
-
for ( int j = 0; j < 4; ++j ) {
|
298
|
-
|
299
|
-
deck[i][j] = Card(i+1,Card::Suit(j));
|
300
|
-
|
301
|
-
}
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
for ( auto& row : deck ) {
|
308
|
-
|
309
|
-
for ( auto& card : row ) {
|
310
|
-
|
311
|
-
cout << setw(16) << card.description();
|
312
|
-
|
313
|
-
myFile << setw(16) << card.description();
|
314
|
-
|
315
|
-
}
|
316
|
-
|
317
|
-
}
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
myFile.close();
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
fstream myFile2;
|
328
|
-
|
329
|
-
myFile2.open("lab.txt");
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
cout << "Enter a number: ";
|
334
|
-
|
335
|
-
cin >> num2;
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
string str;
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
myFile2.seekg(num2 * sizeof(record), ios::beg);
|
344
|
-
|
345
|
-
myFile2.read(reinterpret_cast<char *>(&record), sizeof(record));
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
cin.ignore();
|
350
|
-
|
351
|
-
cin.getline(record.num2, LINE);
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
myFile2.close();
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
system("pwd");
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
return 0;
|
364
|
-
|
365
|
-
}
|
366
|
-
|
367
|
-
|
368
|
-
|
369
353
|
```
|
1
getline()を使いました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -242,7 +242,7 @@
|
|
242
242
|
|
243
243
|
|
244
244
|
|
245
|
-
|
245
|
+
const int LINE = 52;
|
246
246
|
|
247
247
|
|
248
248
|
|
@@ -262,11 +262,27 @@
|
|
262
262
|
|
263
263
|
|
264
264
|
|
265
|
+
struct Inve {
|
266
|
+
|
267
|
+
int num2;
|
268
|
+
|
269
|
+
char buffer[LINE];
|
270
|
+
|
271
|
+
};
|
272
|
+
|
273
|
+
|
274
|
+
|
265
275
|
int main() {
|
266
276
|
|
277
|
+
|
278
|
+
|
279
|
+
Inve record;
|
280
|
+
|
267
281
|
int num2;
|
268
282
|
|
269
|
-
|
283
|
+
//char buffer[LINE];
|
284
|
+
|
285
|
+
|
270
286
|
|
271
287
|
fstream myFile;
|
272
288
|
|
@@ -306,6 +322,8 @@
|
|
306
322
|
|
307
323
|
|
308
324
|
|
325
|
+
|
326
|
+
|
309
327
|
fstream myFile2;
|
310
328
|
|
311
329
|
myFile2.open("lab.txt");
|
@@ -318,19 +336,19 @@
|
|
318
336
|
|
319
337
|
|
320
338
|
|
321
|
-
GoToLine(myFile2, num2);
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
string
|
339
|
+
string str;
|
326
|
-
|
340
|
+
|
341
|
+
|
342
|
+
|
327
|
-
myFile2
|
343
|
+
myFile2.seekg(num2 * sizeof(record), ios::beg);
|
328
|
-
|
329
|
-
|
330
|
-
|
344
|
+
|
331
|
-
|
345
|
+
myFile2.read(reinterpret_cast<char *>(&record), sizeof(record));
|
332
|
-
|
346
|
+
|
347
|
+
|
348
|
+
|
333
|
-
cin.ge
|
349
|
+
cin.ignore();
|
350
|
+
|
351
|
+
cin.getline(record.num2, LINE);
|
334
352
|
|
335
353
|
|
336
354
|
|