Programming/C++
string subscript out of range / C++ 에러
갓비니
2020. 4. 24. 16:59
간단한 에러이다.
범위를 벗어났다는 것임
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int count;
int repeat;
string word;
cin >> count;
for (int i = 0; i < count; i++) {
cin >> repeat;
cin >> word;
for (int j = 0; j < word.size(); j++) {
for (int k = 0; k < repeat; k++) {
cout << word[j];
}
}
cout << "\n";
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
sizeof(word) --> word.size() 바꾸었더니 해결되었다.