We were given a task to use lists and iterators. We were supposed to make them from scratch. I'm done with that. The problems that I'm having are as following: 1. I'm not able to access the list made of Course datatype which is present in each Student instance. Does this mean I need to make an iterator for that course list inside the student class? 2. Similarly since I don't have direct access to The course list so I added the course into the Student list through the student objects not through the iterator. How can I do it …

Member Avatar
Member Avatar
+0 forum 1

Hi, Imagine a vector of structures with each structure containing various variables. struct Data { double x double y double z } vector<Data> Dataset vector<Data>::iterator it //input some data from a file into DataSet How can I iterate over this vector, comparing say, x at the nth row to the x at the (n-1th) row and the x at the (n-2th) row, beginning at n (where n is Dataset.begin() + 2) and moving one n forward at a time? Thanks, TR

Member Avatar
Member Avatar
+0 forum 8

I decided to learn C++ STL and I was exprimenting with STL containers. I saw this example [here](http://www.cplusplus.com/reference/stl/vector/insert/): // inserting into a vector #include <iostream> #include <vector> using namespace std; int main () { vector<int> myvector (3,100); vector<int>::iterator it; it = myvector.begin(); it = myvector.insert ( it , 200 ); myvector.insert (it,2,300); // "it" no longer valid, get a new one: it = myvector.begin(); vector<int> anothervector (2,400); myvector.insert (it+2,anothervector.begin(),anothervector.end()); int myarray [] = { 501,502,503 }; myvector.insert (myvector.begin(), myarray, myarray+3); cout << "myvector contains:"; for (it=myvector.begin(); it<myvector.end(); it++) cout << " " << *it; cout << endl; return 0; } …

Member Avatar
Member Avatar
+0 forum 2

I'm doing some research to determine the most efficient way to copy files. I've got 3 candidate functions: #1 [CODE=python] # uses generator to load segments to memory def copy(src, dst, iteration=1000): for x in xrange(iteration): def _write(filesrc, filedst): filegen = iter(lambda: filesrc.read(16384),"") try: while True: filedst.write(filegen.next()) except StopIteration: pass with open(src, 'rb') as fsrc: with open(dst, 'wb') as fdst: _write(fsrc, fdst)[/CODE] #2 [CODE=python] # loads entire file to memory def copy2(src, dst, iteration=1000): for x in xrange(iteration): with open(src, 'rb') as fsrc: with open(dst, 'wb') as fdst: fdst.write(fsrc.read())[/CODE] #3 [CODE=python] def copy3(src, dst, iteration=1000): for x in xrange(iteration): with …

Member Avatar
Member Avatar
+0 forum 4

[CODE]TreeSet goodWords = new TreeSet(); ... Iterator iterGoodWords = goodWords.iterator(); while (iterGoodWords.hasnext()) { String word = iterGoodWords.next(); System.out.println(word); }[/CODE] Tell me, why doesn’t that print anything even if there are some items in the goodWords collection? I know there are items in the set because when I check the size, it’s not zero. It seems that iterGoodWords.hasnext() always evaluates to false. Javac compiles it. It just doesn’t print.

Member Avatar
Member Avatar
+0 forum 7

The End.