Runtime Error 2.012052ms 404KiB foo.cc: In function 'bool check1(std::string)': foo.cc:16:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 16 | for(int i=1; i<s.size()-1;i++) | ~^~~~~~~~~~~ foo.cc: In function 'bool check2(std::string)': foo.cc:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 24 | for (int i = 0; i < s.size()- 1; i++) | ~~^~~~~~~~~~~~~ foo.cc: In function 'int main()': foo.cc:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 54 | for (int i = 0; i < s.size()- 1; i++) | ~~^~~~~~~~~~~~~ foo.cc:59:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 59 | while(j < s.size() && s[j] >= '0' && s[j] <= '9') n = n * 10 + (s[j++] - '0'); | ~~^~~~~~~~~~ foo.cc:79:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 79 | while(j < s.size() && isdigit(s[j])) n = n * 10 + (s[j++]-'0'); | ~~^~~~~~~~~~ ExitCode: 11 (Segmentation fault)
时间: 2024-04-17 16:26:21 浏览: 83
庖丁解牛分析uboot
非常抱歉,之前的代码存在一些问题。根据您提供的错误信息,看起来可能是由于数组越界导致的段错误。经过仔细检查,我发现在代码中有一处错误。
请将以下两处代码:
```cpp
for (int i = 0; i < s.size()- 1; i++)
```
修改为:
```cpp
for (int i = 0; i < s.size(); i++)
```
这样修改后,代码应该可以正常执行,而不会出现段错误。
再次感谢您的耐心和指出问题的细节。如果您还有其他问题,请随时提问。
阅读全文