Why does this happen my program says that it has no errors but then when I run it and I value sn , temp; I get terminate called after throwing an instance of 'std::out_of_range' what(): vector:_M_range_check. I am new to c++ so I don't understand these errors
#include <iostream>
#include "Region.h"
usingnamespace std;
namespace personalization ;
int main() {
int t ;
for ( cin >> t ; t != 0; t--){ // reads t different test cases .
Region region ;
while(true)
{
int sn , temp;
cin >> sn >> temp;
if (sn == 0 && temp == 0)
break;
region.add_sensor(sn , temp) ;
}
cout<<.......<<endl;
}
return 0;
}
Why does this happen my program says that it has no errors
No. Your compiler says your program is syntactically correct. It does not say that your program contains no errors.
When a Network is constructed how is its sensors member initialized?
When a Region is constructed, how is its r_networks member initialized?
What types are these two members?
You've given very little relevant information/code. In the future, please try to provide a complete but minimal code sample that is compilable and produces the problem you're experiencing. Doing so means you're more likely to get a cogent response.
You still haven't provided the information I asked for.
You would encounter the problem you're having if sensors was empty when it was indexed with at(0), since 0 wouldn't be a valid index. r_networks probably wouldn't have the same result if it were empty, since you're using unchecked access, although some compilers may check the access anyway in debug mode.