C++:,当我使用字符串数组时,它的字符串下标超出了范围
C++:,when i use string array, it comes string subscript out of range
我只想知道为什么会出现字符串下标超出范围的问题,我已经初始化了字符串数组。谢谢。
#include<bits/stdc++.h>
#define N 100000
using namespace std;
string s[N + 5] = {}, ss[N + 5] = { " " }, fs[N + 5] = { " " };
int main()
{
int n, x; char c;
cin >> n;
for (int i = 0; i<n; ++i)
{
for (int j = 0; j<6; ++j)
{
scanf("%c", &c);//the error comes here.
if (c == ' ') continue;
s[i] += c;
}
ss[i] = s[i] + s[i];
for (int j = 5; j >= 0; --j) fs[i][j] = s[i][5 - j];
}
int flag = 0;
for (int i = 0; i<n; ++i)
{
for (int j = 0; j<n; ++j)
{
if (i == j) continue;
if (find(s[i], fs[j]) || find(s[i], ss[j]))
{
flag = 1; break;
}
}
}
}
1(为什么我不应该 #include <bits/stdc++.h>
?
2(避免全局变量,当大小未知时使用std::vector。
3(为什么using namespace std
被认为是不良做法?
由于fs[i][j]
访问空字符串f[i]
,您收到超出范围的错误。
相关文章:
- C++十进制到十六进制(字符串下标超出范围)
- 尝试对字符串[数组]>>cin 并出现错误(" "字符串下标超出范围")
- 字符串下标是关联的索引吗?
- C++:,当我使用字符串数组时,它的字符串下标超出了范围
- 调试断言失败 字符串下标超出范围
- 断言错误,字符串下标超出范围
- 字符串下标超出范围错误"C++"
- 错误字符串下标超出c++范围
- 字符串下标超出范围C++:调试
- C++:表达式:字符串下标超出范围
- C++ 运行程序时字符串下标超出范围
- 字符串下标超出范围
- 字符串下标超出范围.我不知道如何使用字符索引数组,所以我使用了(无符号整数),但它不起作用
- 字符串下标超出范围错误
- C++ 错误:第 1440 行 表达式:字符串下标超出范围
- C++ 字符串下标超出范围
- 使用 c++,为什么我知道它不是时会收到错误消息“字符串下标超出范围”?或者至少看起来是这样
- C++错误:字符串下标超出范围
- 错误:表达式:字符串下标超出范围
- 调试断言失败:表达式:字符串下标超出范围