dev求助
  • 板块灌水区
  • 楼主c_y_y
  • 当前回复8
  • 已保存回复8
  • 发布时间2024/8/21 19:26
  • 上次更新2024/8/21 21:34:46
查看原帖
dev求助
777965
c_y_y楼主2024/8/21 19:26
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 中运行得到的错误代码。求原因()。

#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;
}

2024/8/21 19:26
加载中...