我试图建立一个相对复杂的数据结构(对我来说)。我的目标是从文本文档中读取单词,并将单词和一些特定属性编入一个散列表。该表由结构向量构成:(向量<向量> vecName;)。我很幸运。每个唯一字被散列到向量中的索引位置。矢量的第二维(结构向量)存储有关正在读取的文件的信息以及文件中找到的单词的位置。对于我读取的每个文件,如果我多次查找某个单词,则会在结构中增加一个计数,并且带有整数的结构向量将存储单词存储在文件中的所有位置的信息。我可以用结构向量构建一个结构向量向量吗? (是的,真的)
我有两个项目,我想与援助:
- 我很好奇,如果任何人有更好的数据结构实现比我建议的建议。包含一些独立数据成员而不是这个庞然大物的类可能更有用吗?
- 看来我的语法错误是导致编译错误,或者我试图构建一个向量类不支持的结构。
这里是cmpilation错误。所有这三个错误是指结构的载体结构内:
“类的std ::矢量>”没有名为“theLoc”
“类的std ::矢量>”没有名为“theStart”成员成员
“类的std ::矢量>”没有名为成员“附带一份最终”
如果我调整代码为EboMike表明,原来的错误消失,但后来我得到:
我得到一个不同的错误我不能发布,因为编辑认为我发布超链接。总结如下:*'请求'testProps.wordProps :: theWordLoc:theLoc中的成员'push_back',它是非类类型'int'*
这里是我的代码和一个图的链接
#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>
using namespace std;
struct wordLoc
{
int theLoc; // the location of the word in theFile
int theStart; // the beginning of the sentence
int theEnd; // the end of the sentence
};
struct wordProps // stores word info to be placed in array
{
string theFile; // stores the file where theWord is found
int theCount; // increments with each occurence of theWord
vector <wordLoc> theWordLoc; // stores the wordLoc info for each occurence of theWord
};
int main()
{
int Tsize = 20000;
wordProps testProps;
testProps.theFile = "test1";
testProps.theCount = 1;
testProps.theWordLoc.theLoc.push_back(200);
testProps.theWordLoc.theStart.push_back(1);
testProps.theWordLoc.theEnd.push_back(15);
vector < vector <wordProps> > theWordProps;
theWordProps.resize(Tsize);
theWordProps[0].push_back(testProps);
cout << "index[0] = " << theWordProps[0].front().theFile << endl;
cout << "index[0] = " << theWordProps[0].front().theCount << endl;
cout << "index[0] = " << theWordProps[0].front().theWordLoc[0].theLoc << endl;
cout << "index[0] = " << theWordProps[0].front().theWordLoc[0].theStart << endl;
cout << "index[0] = " << theWordProps[0].front().theWordLoc[0].theEnd << endl;
cout << "size of theWordProps[0] = " << theWordProps[0].size();
cout << endl;
}
“看来,我要么就导致一个编译错误语法错误” ......请张贴错误消息的全文。 – 2010-12-04 06:48:49