Hello,
I found following source code:
Code:
void func_read(istream&, vector<string>&);
void func_read_file(ifstream&, vector<string>);
//and implementations
void func_read(istream& in, vector<string>& v)
{
string s;
while( in >> s )
{
v.push_back(s);
}
}
void func_read_file(ifstream& in, vector<string> v)
{
string s;
while( in >> s )
{
v.push_back(s);
}
}
I really don't know why this is written like this, I tested func_read:
Code:
int main()
{
vector<string> v;
ifstream in("test.txt");
func_read( in, v );
vector<string>::const_iterator it;
for(it = v.begin(); it != v.end(); ++it)
cout<<*it<<endl;
}
and everything seem to be OK, and it works fine since istream can accept referece to ifstream. So I assume there is no need to write special function to read from file (ifstream&).
Can you confirm this?
Is there any situations where this approach is necessary?
Thanks very much