I'm trying to get input with spaces in my code and I figured out using get line() so when I'm trying to use it inside loop but when It enters the loop it throws an exception terminating with uncaught exception of type std::out_of_range: basic_string Aborted
So how to fix it?
My Code:
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
int N, Q;
map<pair<string, string>,string> DATA;
cin>>N;
while(N--){
string Code;
getline(cin,Code);
for(int i=0;i<Code.length();i++){
if(Code[i]==' '){
Code.erase(Code.begin()+i);
}
}
string Tag,Data,Type;
Tag=Code.substr(1,4);
int Start=Code.find('"');
for(int i=Start+1;i<Code.length();i++){
Data.push_back(Code[i]);
if(Code[i]=='>'){
Data.pop_back();
Data.pop_back();
break;
}
}
for(int i=5;i<Code.length();i++){
Type.push_back(Code[i]);
if(Code[i]=='='){
Type.pop_back();
break;
}
}
DATA.emplace(make_pair(Type,Tag),Data);
}
string Print;
cin>>Print;
string tag_n,type_n;
tag_n=Print.substr(0,4);
type_n=Print.substr(5,Print.length());
pair<string,string>Val={type_n,tag_n};
if(DATA.find(Val)!=DATA.end()){
cout<<DATA[Val];
}
else{
cout<<"Not Found!";
}
}
PS:
Thanks for reading
Sorry for bad English