Not sure why it isn't drawing that one line, but you can clean up your code like this
void printvec(const vector<vec2D> &v){
RenderWindow win(VideoMode(1000, 1000), "screen");
win.Clear(sf::Color::Black);
for(vector<vec2D>::iterator it = v.begin() i1=0; it != v.end(); ++it){
it->Draw(win);
it->Print();
}
win.Display();
while (win.IsOpened()){
Event Event;
while (win.GetEvent(Event)){
//Sluit het scherm
if (Event.Type == Event::Closed){//het scherm sluiten
win.Close();
}
}
}
return;
}
1. Your picture isn't changing so I'm not sure why you're drawing it twice.
2. If you're using STL's vector template, you don't need to pass in the size, you can use iterators
3. Put the drawing/printing functionality into the vec2D function
4. Why do you have 5 zero vectors?
5. What is the functionality of vec2D supposed to be? In maths a 2D vector is two pieces of information, x and y. It shouldn't have a starting point. Maybe you should rename it to LineSegment or something.
6. Prefer passing in by reference to const rather than by copy. If you intend to change the vector v then take the const out on the first line.
7. Did you use "using namespace sf"? Sometimes you use sf:: and sometimes you don't. Try to be consistent
Here is how you should put the drawing functionality in your class vec2D
class vec2D {
public:
void Draw(sf::RenderWindow &win) const {
win.Draw(Shape::Line(getStartX(), getStartY(), getStartX()+getVecX(), getStartY()+ getVecY(), 2, sf::Color::Green));
return;
}
void Print() const {
cout <<getStartX()<<' '<<getStartY()<<' '<<getStartX()+getVecX()<<' '<<getStartY()+getVecY()<<endl;
}
};