Hello,
I found following source code:
I really don't know why this is written like this, I tested func_read: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); } }
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&).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; }
Can you confirm this?
Is there any situations where this approach is necessary?
Thanks very much



LinkBack URL
About LinkBacks


