社区讨论
dev求助
灌水区参与者 6已保存回复 8
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 8 条
- 当前快照
- 1 份
- 快照标识符
- @m03rr99y
- 此快照首次捕获于
- 2024/08/21 19:27 2 年前
- 此快照最后确认于
- 2024/08/21 21:34 2 年前
CPP
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr: __pos (which is 1) > this->size() (which is 0)
在 exe 中运行得到的错误代码。求原因()。
CPP#include <bits/stdc++.h>
using namespace std;
const int M=30,P=110;
map<string,int>inx;
struct node{
string name,say;
}a[P];
int main() {
//cin.tie(0),cout.tie(0);
//ios::sync_with_stdio(false);
int m,n,p;
cin>>m>>n>>p;
for(int i=1;i<=m;i++){
string name;
cin>>name;
inx[name]=i;
}
for(int i=1;i<=p;i++){
string s;
getline(cin,s);
string name="";
int j;
for(j=0;j<s.size();j++){
if(s[j]==':') break;
name+=s[j];
}
a[i].name=name;
j++;
a[i].say=s.substr(j,s.size()-j);
}
for(int i=1;i<=p;i++) cout<<a[i].name<<" "<<a[i].say<<"\n";
return 0;
}
回复
共 8 条回复,欢迎继续交流。
正在加载回复...