#include <string>
#include <fstream>
#include <iostream>
struct Personel_record
{
std::string Name;
int StartSalary;
int Age;
};
struct dog
{
std::string breed;
int age;
};
std::istream& operator>>(std::istream& is, Personel_record& pr)
{
Personel_record new_pr;
if( is >> std::ws
&& std::getline(is, new_pr.Name, '~')
&& is >> new_pr.StartSalary >> new_pr.Age )
{
pr = new_pr; // could do more validation here
}
return is;
}
std::istream& operator>>(std::istream& is, dog& doggy)
{
dog new_doggy;
if( std::getline(is, new_doggy.breed, '~')
&& is >> new_doggy.age )
{
doggy = new_doggy;
}
return is;
}
int main()
{
std::ifstream indata("test.txt");
std::ifstream indog("dog.txt");
Personel_record pr;
while(indata >> pr)
{
std::cout << "complete"; //if i comprehend the IN I should get the OUT
}
dog doggy;
while(indata >> doggy)
{
std::cout << "complete"; //if i comprehend the IN I should get the OUT
}
}
}
The above is just a guess - but if I am on the right track - what connects while(indata >> pr) and while(indata >> doggy)to thier proper stream functions. HOpe I said this correctly?
since pr and dog are not simple types of variables like int or char or double but instead structs - I am asuming c++ in this case will look for a function to resolve the request . It will use the function that contains the proper variable parameters - In this case istream and the correct stuct - so pr looks for the parameter of personal_records and doggy looks for the parameter of dog????
hey Iamk2...I tried your method in the linux forum but I get:
bash: /etc/modules: Permission denied
any help?
please reply on forum post broadcom802.11 issues...well..you know the place
The functions defined on Lines 18 and 30 are what "connects" the stream and object type with their proper function call. This is called operator overloading, it tells the program what to do when it sees the operator you specify associated with the data types that you pass as arguments.