我試圖建立一個相對複雜的數據結構(對我來說)。我的目標是從文本文檔中讀取單詞,並將單詞和一些特定屬性編入一個散列表。該表由結構向量構成:(向量<向量> 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