3 ms·
Traditional C++ would look something like this: for (vector<string>::const_iterator it = data.begin(); it != data.end(); ++it) { ofile << *it << endl
by pdw 13y ago
Traditional C++ would look something like this:
for (vector<string>::const_iterator it = data.begin(); it != data.end(); ++it) {
ofile << *it << endl;
}
But in this case we're dealing with a vector, so you don't need iterators:
for (unsigned i = 0; i < data.size(); ++i) {
ofile << data[i] << endl;
}
- alexchamberlain 13y agoUgh, define need. If sanity is required, stick to iterators.
- mrich 13y agoIterators can get very ugly. I like this when there is a need to access elem a lot inside the loop: for (size_t i = 0, iEnd = elems.size(); i < iEnd; ++i) { Elem &elem = elems[i]; // deal with elem } Of course the new C++11 syntax is king.