交换结构的向量 [英] Interate a vector of struct
本文介绍了交换结构的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个结构的向量。这很简单但是当我尝试为它定义一个迭代器时,我在第23行(我尝试声明交互器的最后一行)得到了这个错误。
template< class _Tp,类_Alloc> class std :: vector'在没有模板参数的情况下使用。以下是所有代码
#include < vector >
struct 字段{
int idFieldsid;
char * FieldId;
char *姓名;
int 类型;
int 长度;
int FieldPrecision;
char * isPrimaryKey;
char * isRequired;
char * fieldVisible;
char * EmumValues;
};
使用 命名空间标准;
int main()
{
vector< Field> FieldsResults;
vector ::< Field> :: std :: iterator FieldsResultsit;
}
我的尝试:
我试过谷歌搜索这个,但所有的答案给出了一个复杂的解释,但没有一个很好的例子。我希望得到一些示例代码来修复这个
解决方案
你的迭代器声明是错误的,它应该是:
< pre lang =c ++> vector< Field> :: iterator FieldsResultsit;
// 不
// vector :: < Field> :: std :: iterator FieldsResultsit; 跨度>
I need to have a vector of a struct. That's easy but when I try to define a iterator for it I get this error on line 23 (the last line where I try to declare the interator)
template<class _Tp, class _Alloc> class std::vector’ used without template parameters. Here is all the code
#include <vector>
struct Field{
int idFieldsid;
char* FieldId;
char* Name;
int Type;
int Length;
int FieldPrecision;
char* isPrimaryKey;
char* isRequired;
char*fieldVisible;
char* EmumValues;
} ;
using namespace std;
int main()
{
vector<Field> FieldsResults;
vector::<Field>::std::iterator FieldsResultsit;
}
What I have tried:
I tried googling this but all the answers gave a complex explanation but no good example. I'm hoping to get some sample code to fix this
解决方案
Your declaration of the iterator is wrong, it should be:
vector<Field>::iterator FieldsResultsit; // not // vector::<Field>::std::iterator FieldsResultsit;
这篇关于交换结构的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文