//flex table opened by JP

Click to See Complete Forum and Search --> : An awesome std::vector question lol


nothing
09-15-2004, 10:58 AM
I have a std::vector of type std::string and it if filled with filenames. I want to create files using each filename that is in the vector and this is what I've done so far:


std::vector<std::string>::const_iterator iterator = 0; // I have no idea if this is correct
while(number_of_pages != 0){

std::ofstream html(files[*iterator].c_str());

// increment iterator


Can you guys understand what I mean? The problem is that it doesn't work :D
Can somebody help me please? Thanks.

CompGeek01
09-15-2004, 02:36 PM
I'm pretty sure the syntax is:


std::vector<std::string>::const_iterator i = myVector.begin());

while( i != myVector.end() )
{
std::cout << *i;
i++;
}


Am i thinking something else?

nothing
09-15-2004, 02:49 PM
I got it.

for(iterator = files.begin(); iterator != files.end(); iterator++)

std::ofstream html(iterator->c_str());


:t

nothing
09-15-2004, 04:35 PM
I have another little problem:

for(iterator_links = files.begin(); iterator_links != files.end(); iterator_links++){
if(iterator_links == auxiliary){
html << '[' << auxiliary << ']' << ' ';
continue;
}
}


iterator_links looks like this:

std::vector<std::string>::const_iterator iterator_links;


auxiliary is an int and at first it is equal to 1. Why doesn't the if statement execute? Thanks.

CompGeek01
09-15-2004, 06:09 PM
I can't seem to find a way to convert the iterator to an integer...you might just have to make another local veriable?

nothing
09-15-2004, 06:39 PM
Here's a piece of the code:

for(iterator_links = files.begin(); iterator_links != files.end(); iterator_links++){
if(iterator_links == auxiliary){
html << '[' << auxiliary << ']' << ' ';
continue;
}

html << "<a href=\"" << *iterator_links << "\">" << auxiliary << "</a>\n";

auxiliary++;
}


How would you do it? I can't think of a way :(

CompGeek01
09-15-2004, 08:39 PM
Thats the strangest thing. I tried some interesting things....i have come to beleive the iterator doesn't know where it is I guess....Maybe use a sad work around to keep track of the position? Thats what you mainly want right?


int i = 0;
for(iterator_links = files.begin(); iterator_links != files.end(); iterator_links++, i++){