S
sd2004
Hi ,
could someone please help ?
What I would like to do is to skip line with # .
/////// Error message ////////////////////////////////
test7.cpp: In function `std::istream& operator>>(std::istream&,
astruct&)':
test7.cpp:18: error: `find' undeclared (first use this function)
test7.cpp:18: error: (Each undeclared identifier is reported only once
for each
function it appears in.)
test7.cpp:18: error: continue statement not within a loop
///////////// input file "test7.txt" //////////////////
################################
N Kait 555 2124.80 5.5
Y Tina 777 9184.30 8.2
################################
///////////////////// source code "test7.cpp" ////////////////////
#include<iostream>
#include <string>
#include<vector>
#include<sstream>
#include<fstream>
using namespace std;
class astruct
{
public:
string skip;
string name;
int id;
float loan;
float interest_rate;
};
istream& operator>>(istream& is, astruct& s){
// Just want to skip line with #
if(is.find("#")!=string::npos) continue; // this cause the progam
NOT compile.
is >>s.skip>>s.name >> s.id >>s.loan >> s.interest_rate;
return is;
}
int main()
{
vector<astruct> v;
astruct astr;
ifstream in ("test7.txt");
if(!in) {cout << "cannot open file"<<endl;}
string line;
while (in>>astr){
v.push_back(astr);
}
vector<astruct> ::iterator test;
for (test=v.begin();test!=v.end();++test){
if (test->skip.find("Y")!=string::npos)continue;
float total_due = test->loan * test->interest_rate;
cout <<"Name : "<<test->name<<" "<<" ID: "<<test->id<<" Loan: "
<<test->loan<<" Principal: "<<total_due<< endl;
}
return 0;
}
could someone please help ?
What I would like to do is to skip line with # .
/////// Error message ////////////////////////////////
test7.cpp: In function `std::istream& operator>>(std::istream&,
astruct&)':
test7.cpp:18: error: `find' undeclared (first use this function)
test7.cpp:18: error: (Each undeclared identifier is reported only once
for each
function it appears in.)
test7.cpp:18: error: continue statement not within a loop
///////////// input file "test7.txt" //////////////////
################################
N Kait 555 2124.80 5.5
Y Tina 777 9184.30 8.2
################################
///////////////////// source code "test7.cpp" ////////////////////
#include<iostream>
#include <string>
#include<vector>
#include<sstream>
#include<fstream>
using namespace std;
class astruct
{
public:
string skip;
string name;
int id;
float loan;
float interest_rate;
};
istream& operator>>(istream& is, astruct& s){
// Just want to skip line with #
if(is.find("#")!=string::npos) continue; // this cause the progam
NOT compile.
is >>s.skip>>s.name >> s.id >>s.loan >> s.interest_rate;
return is;
}
int main()
{
vector<astruct> v;
astruct astr;
ifstream in ("test7.txt");
if(!in) {cout << "cannot open file"<<endl;}
string line;
while (in>>astr){
v.push_back(astr);
}
vector<astruct> ::iterator test;
for (test=v.begin();test!=v.end();++test){
if (test->skip.find("Y")!=string::npos)continue;
float total_due = test->loan * test->interest_rate;
cout <<"Name : "<<test->name<<" "<<" ID: "<<test->id<<" Loan: "
<<test->loan<<" Principal: "<<total_due<< endl;
}
return 0;
}