A
anant
Hi all
The below code is reading string and then tokenizin it and reading all
the info. But i want to call a csv file and it should then read a
string from dt file. So what midification should i do in the below
code. Its main code, all the functions are defined well. So just wanna
know how to include some extra code to open the file and read each
line.
Thanks a lot
typedef struct
{
string firstName;
string surname;
unsigned int HouseNumber;
string StreetName;
string Town;
unsigned int PostCode;
string email;
unsigned int Phone;
}Person;
int main(int argc, char* argv[])
{
string data = "James,Bond,
33,AlberStreet,Manchester,HG231,[email protected],2552423";
string delimiter = ",";
StringTokenizer strtok(data,delimiter);
StringTokenizer strtok(data,delimiter);
if(strtok.countTokens() != 8)
{
cout << "!-Error-! Not enough tokens!" << std::endl;
}
else
{
Person person;
person.firstName = strtok.nextToken();
person.surname = strtok.nextToken();
person.HouseNumber = strtok.nextIntToken();
person.StreetName = strtok.nextToken();
person.Town = strtok.nextToken();
person.PostCode = strtok.nextIntToken();
person.email = strtok.nextToken();
person.Phone = strtok.nextIntToken();
}
}
The below code is reading string and then tokenizin it and reading all
the info. But i want to call a csv file and it should then read a
string from dt file. So what midification should i do in the below
code. Its main code, all the functions are defined well. So just wanna
know how to include some extra code to open the file and read each
line.
Thanks a lot
typedef struct
{
string firstName;
string surname;
unsigned int HouseNumber;
string StreetName;
string Town;
unsigned int PostCode;
string email;
unsigned int Phone;
}Person;
int main(int argc, char* argv[])
{
string data = "James,Bond,
33,AlberStreet,Manchester,HG231,[email protected],2552423";
string delimiter = ",";
StringTokenizer strtok(data,delimiter);
StringTokenizer strtok(data,delimiter);
if(strtok.countTokens() != 8)
{
cout << "!-Error-! Not enough tokens!" << std::endl;
}
else
{
Person person;
person.firstName = strtok.nextToken();
person.surname = strtok.nextToken();
person.HouseNumber = strtok.nextIntToken();
person.StreetName = strtok.nextToken();
person.Town = strtok.nextToken();
person.PostCode = strtok.nextIntToken();
person.email = strtok.nextToken();
person.Phone = strtok.nextIntToken();
}
}