I have these 2 related files:
PERSON.H::
#include<iostream>
#include<string.h>
using namespace std;
class Person
{
private:
string Name;
string Surname;
float Height;
long long PhoneNo;
string Nickname;
public:
Person(string, string, float, long long, string);
inline string getName(){return Name;}
inline string getSurname(){return Surname;}
inline float getHeight(){return Height;}
inline long long getPhoneNo(){return PhoneNo;}
inline string getNickname(){return Nickname;}
bool operator<(Person &);
bool operator>(Person &);
friend ostream& operator<<(ostream &,Person &);
};
PERSON.CPP
#include<iostream>
using namespace std;
#include "Person.h"
#include <vector>
#include <map>
#include <utility>
Person::Person(string s1,string s2,float f1,long long l1,string s3)
{
this->Name=s1;
Surname=s2;
Height=f1;
PhoneNo=l1;
Nickname=s3;
}
ostream & operator<<(ostream &os,Person &p)
{
os<<p.getName()<<" "<<p.getSurname()<<"||"<<p.getHeight()<<"||"<<p.getPhoneNo()<<"||"<<p.getNickname()<<endl;
return os;
}
int main(int argc,char **args)
{
int count=stoi(args[1]);
cout<<count<<endl;
vector <Person> vp;
map <long long, Person> pm;
for(int i=0;i<count;i++)
{
string name,surname,nickname,heightstr,phonenostr;
float height;
long long phoneno;
cout<<"Input Name: ";
cin>>name;
cout<<endl;
cout<<"Input Surname: ";
cin>>surname;
cout<<endl;
cout<<"Input Height: ";
cin>>height;
cout<<endl;
cout<<"Input Phone no. : ";
cin>>phoneno;
cout<<endl;
cout<<"Input Nickname: ";
cin>>nickname;
cout<<endl;
Person p(name,surname,height,phoneno,nickname);
vp.push_back(p);
pair<long long,Person> pr(phoneno,p);
pm.insert(pr);
}
for(auto i=vp.begin();i!=vp.end();i++)
cout<<*i<<endl;
for(auto it=pm.begin();it!=pm.end();it++)
cout<<it->first<<":"<<it->second<<endl;
return 0;
}
However whenerver i try to run it on Codeblocks it simply gives me a :
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_M_construct null not valid
error on the output screen. I ran this on Linux during my classes and it working fine though.
I have changed the internal compiler to run on both c++11 and c++14 and yet i kept getting the same message. Only after replacing
int count=stoi(args[1]);
cout<<count<<endl;
part with
int count;
cout<<"Enter number of input runs: ";
cin>>count;
made the code run on Codeblocks. Am i missing some part of the configuration in Codeblocks or am i using some compiler wrongly?