I'm getting an error when I use the iterator member function "empty()" on vector of type int, but not vector of type string (using the correct terms to the best of my understanding).
vector of type int:
#include <iostream>
#include <string>
#include <vector>
int main()
{
vector<int> ivec = {0,1,2};
auto iter = ivec.begin();
if(!iter->empty())
cout << "not empty" << endl;
return 0;
}
Output:
error C2839: invalid return type 'int *' for overload 'operator ->'
error C2039: 'empty': is not a member of 'std::Vector_iterator....'
vector of type string:
#include <iostream>
#include <string>
#include <vector>
int main()
{
vector<string> svec = {"text"};
auto iter = svec.begin();
if(!iter->empty())
cout << "not empty" << endl;
return 0;
}
Output:
not empty
Aucun commentaire:
Enregistrer un commentaire