S
sd2004
Coudl someone make the following code more elegant ?
#include<iostream>
#include <string>
#include<vector>
#include<sstream>
#include<fstream>
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,line)){
istringstream anyname(line);
anyname>>astr.name>>astr.id;
v.push_back(astr);
}
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<iostream>
#include <string>
#include<vector>
#include<sstream>
#include<fstream>
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,line)){
istringstream anyname(line);
anyname>>astr.name>>astr.id;
v.push_back(astr);
}
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