When should we use vectors and when to use normal arrays. Also in one of my codes i found a weird problem.
class TwoTrains
{
public:
int pass(int t1, int t2, vector <int>);
};
int TwoTrains::pass(int t1, int t2, vector <int> times)
{
int size_of_array=(int)times.size();
for(int i=0;i<size_of_array;i++)
{
cout<<times[i]<<endl;
}
return 0;
}
This Compiles but when i use this it gives an error.Why –
for(int i=0; i< times.size();i++)
vectoris what you want. Give arrays for plain-C users.Gives no errors, but warning (Comparing
signedwithunsigned). Useor
As you don’t need indexes, use iterators, as 0A0D notice:
or even
with C++11