Writing to a file.

So lately, I've been experimenting with Qt and I'm loving it thus far.
What impressed me very much was how easy it is to write variables to a file.
For example the container QMap myvar.

I'd just write
in >> myvar
out << myvar

It's as simple as that.
I'm pretty sure you can't do this with, let's say a vector.
But I'm just making sure :)
quick answer would be much appreciated :D
well, you could write
1
2
3
4
5
6
7
template<typename T>
std::istream& operator >> (std::istream& file, std::vector<T>& vec){
   T t;
   file >> t;
   vec.push_back(t);
   return file;
}
or something like that anyway..
(Though on the other hand, I don't think T could be deduced from std::vector<T>..
I'm not sure it there is a way then. Unless you write the operator for strings only, of course)
edit: yeah, a reference..
Last edited on
T would be deducible from that

(although vec should be a reference.)
Topic archived. No new replies allowed.