S
sd2004
Could someone please help ?
I am getting "segmentation fault (core dumped)"
Please explain and show me how to fix the issue.
Thanks in advance for your time.
///////////////// OUTPUT and ERROR MESSAGE ////////////////////
Name : Kait ID: 555 Loan: 2124.8 Principal: 11686.4
Name : Tina ID: 111 Loan: 9184.3 Principal: 56942.7
Name : ID: 0 Loan: 0 Principal: 0
Segmentation fault (core dumped)
////////////////// INPUT FILE : "test6.txt" //////////////////
Kait 555 2124.80 5.5
Tina 111 9184.30 6.2
EOT
/////////////////////// CODE ///////////////////
#include<iostream>
#include <string>
#include<vector>
#include<sstream>
#include<fstream>
using namespace std;
class astruct
{
friend istream &operator>>(istream &,astruct &);
public:
string name;
int id;
float loan;
float interest_rate;
//more ...
// ....
};
istream& operator>>(istream& is, astruct& s){
is >>s.name >> s.id >>s.loan >> s.interest_rate;
return is;
}
int main()
{
vector<astruct> v;
astruct astr;
astruct* astr_ptr;
ifstream in ("test6.txt");
if(!in) {cout << "cannot open file"<<endl;}
string line;
while (in>>astr){
v.push_back(astr);
}
for (astr_ptr=&v[0];astr_ptr->name!="EOT";astr_ptr++){
// I am using for loop so that I can access the data and manipulate
them
//
// ....
// ....
// just an example below:
float total_due = astr_ptr->loan * astr_ptr->interest_rate;
cout<<"Name : "<<astr_ptr->name<<" "<<" ID: "<<astr_ptr->id<<" Loan: "
<<astr_ptr->loan<<" Principal: "<<total_due<< endl;
}
return 0;
}
I am getting "segmentation fault (core dumped)"
Please explain and show me how to fix the issue.
Thanks in advance for your time.
///////////////// OUTPUT and ERROR MESSAGE ////////////////////
Name : Kait ID: 555 Loan: 2124.8 Principal: 11686.4
Name : Tina ID: 111 Loan: 9184.3 Principal: 56942.7
Name : ID: 0 Loan: 0 Principal: 0
Segmentation fault (core dumped)
////////////////// INPUT FILE : "test6.txt" //////////////////
Kait 555 2124.80 5.5
Tina 111 9184.30 6.2
EOT
/////////////////////// CODE ///////////////////
#include<iostream>
#include <string>
#include<vector>
#include<sstream>
#include<fstream>
using namespace std;
class astruct
{
friend istream &operator>>(istream &,astruct &);
public:
string name;
int id;
float loan;
float interest_rate;
//more ...
// ....
};
istream& operator>>(istream& is, astruct& s){
is >>s.name >> s.id >>s.loan >> s.interest_rate;
return is;
}
int main()
{
vector<astruct> v;
astruct astr;
astruct* astr_ptr;
ifstream in ("test6.txt");
if(!in) {cout << "cannot open file"<<endl;}
string line;
while (in>>astr){
v.push_back(astr);
}
for (astr_ptr=&v[0];astr_ptr->name!="EOT";astr_ptr++){
// I am using for loop so that I can access the data and manipulate
them
//
// ....
// ....
// just an example below:
float total_due = astr_ptr->loan * astr_ptr->interest_rate;
cout<<"Name : "<<astr_ptr->name<<" "<<" ID: "<<astr_ptr->id<<" Loan: "
<<astr_ptr->loan<<" Principal: "<<total_due<< endl;
}
return 0;
}