Coudl someone make the following code more elegant ?
#include<iostre am>
#include <string>
#include<vector >
#include<sstrea m>
#include<fstrea m>
using namespace std;
struct astruct
{
string name;
int id;
};
int main()
{
vector<astruct> v;
astruct astr;
astruct* sp;
ifstream in ("test5.txt" );
string line;
while (getline(in,lin e)){
istringstream anyname(line);
anyname>>astr.n ame>>astr.id;
v.push_back(ast r);
}
sp=&v[0];
for (sp=&v[0];sp->name!="EOT";sp ++){
cout<<"Name : "<<sp->name<<" "<<"ID: "<<sp->id<<endl;
}
return 0;
}
///////////////////////input file =test5.txt
///////////////////////////////
Tom 777
Idaho 555
China 111
Cricket 333
EOT
#include<iostre am>
#include <string>
#include<vector >
#include<sstrea m>
#include<fstrea m>
using namespace std;
struct astruct
{
string name;
int id;
};
int main()
{
vector<astruct> v;
astruct astr;
astruct* sp;
ifstream in ("test5.txt" );
string line;
while (getline(in,lin e)){
istringstream anyname(line);
anyname>>astr.n ame>>astr.id;
v.push_back(ast r);
}
sp=&v[0];
for (sp=&v[0];sp->name!="EOT";sp ++){
cout<<"Name : "<<sp->name<<" "<<"ID: "<<sp->id<<endl;
}
return 0;
}
///////////////////////input file =test5.txt
///////////////////////////////
Tom 777
Idaho 555
China 111
Cricket 333
EOT
Comment