回答編集履歴
3
ソース修正
test
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
std::cin >> s >> i;
|
44
44
|
|
45
|
-
if(i >
|
45
|
+
if(i > s.length( )) {
|
46
46
|
|
47
47
|
std::cerr << "Out of range!" << std::endl;
|
48
48
|
|
2
ソース追記
test
CHANGED
@@ -3,3 +3,57 @@
|
|
3
3
|
最初のは、「intとstringを比較してる」って、言われています。
|
4
4
|
|
5
5
|
[std::basic_string::length](https://cpprefjp.github.io/reference/string/basic_string/length.html)
|
6
|
+
|
7
|
+
//
|
8
|
+
|
9
|
+
```text
|
10
|
+
|
11
|
+
usr ~/Project/test % ./a.out
|
12
|
+
|
13
|
+
123456 7
|
14
|
+
|
15
|
+
Out of range!
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
usr ~/Project/test % ./a.out
|
20
|
+
|
21
|
+
123456 4
|
22
|
+
|
23
|
+
4
|
24
|
+
|
25
|
+
usr ~/Project/test % cat t1.cpp
|
26
|
+
|
27
|
+
#include <iostream>
|
28
|
+
|
29
|
+
#include <string>
|
30
|
+
|
31
|
+
//
|
32
|
+
|
33
|
+
int main(void)
|
34
|
+
|
35
|
+
{
|
36
|
+
|
37
|
+
std::string s;
|
38
|
+
|
39
|
+
std::size_t i;
|
40
|
+
|
41
|
+
//
|
42
|
+
|
43
|
+
std::cin >> s >> i;
|
44
|
+
|
45
|
+
if(i >= s.length( )) {
|
46
|
+
|
47
|
+
std::cerr << "Out of range!" << std::endl;
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
std::cout << s[i-1] << std::endl;
|
52
|
+
|
53
|
+
//
|
54
|
+
|
55
|
+
return 0;
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
```
|
1
追記
test
CHANGED
@@ -1,3 +1,5 @@
|
|
1
1
|
まず、エラーメッセージをちゃんと読んで下さい。
|
2
2
|
|
3
3
|
最初のは、「intとstringを比較してる」って、言われています。
|
4
|
+
|
5
|
+
[std::basic_string::length](https://cpprefjp.github.io/reference/string/basic_string/length.html)
|