S
sd2004
Hi,
I do not know why I am getting extra output line.
If someone please help/explain.
Thanks in advance for your time,
///////////////// Source code /////////////
#include<iostream>
#include <string>
#include<vector>
#include<sstream>
#include<fstream>
using namespace std;
class astruct
{
public:
string name;
int id;
string type;
};
#define goldenretriever 11
#define Lab 33
#define Boxer 44
#define Terrier 55
void dog_name (const string& name,const string& type);
int main()
{
vector<astruct> v;
astruct astr;
ifstream in ("test5c.txt");
string line;
while (!getline(in,line).eof()){
istringstream anyname(line);
anyname>>astr.name>>astr.id>>astr.type;
v.push_back(astr);
}
vector<astruct>::iterator search;
for (search=v.begin();search!=v.end();++search){
switch (search->id){
case goldenretriever:
dog_name(search->name,search->type);
break;
case Lab:
dog_name(search->name,search->type);
break;
case Boxer:
dog_name(search->name,search->type);
break;
case Terrier:
dog_name(search->name,search->type);
break;
default:
break;
}
}
return 0;
}
void dog_name (const string& name,const string& type){
cout <<name <<" is " <<type<<endl;
}
///////////// input file "test5c.txt" //////////////////////
cricket 11 GoldenRetriever
nitro 11 GoldenRetriever
Maxtor 33 Lab
Arron 44 Boxer
Dora 55 Terrier
///////////// output from program ////////////////
cricket is GoldenRetriever
nitro is GoldenRetriever
Maxtor is Lab
Arron is Boxer
Dora is Terrier
Dora is Terrier
I do not know why I am getting extra output line.
If someone please help/explain.
Thanks in advance for your time,
///////////////// Source code /////////////
#include<iostream>
#include <string>
#include<vector>
#include<sstream>
#include<fstream>
using namespace std;
class astruct
{
public:
string name;
int id;
string type;
};
#define goldenretriever 11
#define Lab 33
#define Boxer 44
#define Terrier 55
void dog_name (const string& name,const string& type);
int main()
{
vector<astruct> v;
astruct astr;
ifstream in ("test5c.txt");
string line;
while (!getline(in,line).eof()){
istringstream anyname(line);
anyname>>astr.name>>astr.id>>astr.type;
v.push_back(astr);
}
vector<astruct>::iterator search;
for (search=v.begin();search!=v.end();++search){
switch (search->id){
case goldenretriever:
dog_name(search->name,search->type);
break;
case Lab:
dog_name(search->name,search->type);
break;
case Boxer:
dog_name(search->name,search->type);
break;
case Terrier:
dog_name(search->name,search->type);
break;
default:
break;
}
}
return 0;
}
void dog_name (const string& name,const string& type){
cout <<name <<" is " <<type<<endl;
}
///////////// input file "test5c.txt" //////////////////////
cricket 11 GoldenRetriever
nitro 11 GoldenRetriever
Maxtor 33 Lab
Arron 44 Boxer
Dora 55 Terrier
///////////// output from program ////////////////
cricket is GoldenRetriever
nitro is GoldenRetriever
Maxtor is Lab
Arron is Boxer
Dora is Terrier
Dora is Terrier