2

所以我为我的 compsci 课程设置了一个实验室,而教授和助教使用 Eclipse,但是我无法让它正常运行,所以我尝试使用 Visual Studio。我遇到的问题是我无法让我的程序读取我想要的文本文件,以便它可以执行它需要的操作。

这是我下面的代码:

struct wordpair { string key; string following; };

int compare(wordpair a, wordpair b) {
if (a.key  < b.key) return -1;
if (a.key == b.key) return  0;
if (a.key  > b.key) return  1;
}

int main() {
ArrayDeque<string> A;
Treap1<wordpair> bst;
string k, l;

ifstream textstream("c:\\Users\\Jay\\Documents\\textfile.txt");
int t = clock();
textstream >> k;
A.add(0, k);
// insert wordpairs
while (textstream >> l) {
    wordpair w;
    w.key = k; w.following = l;
    bst.add(w);
    k = l;
    A.add(0, k);
}
// do some searches
for (int i = 0; i < 3*A.size(); ++i){
    wordpair w;
    w.key = A.get(rand()%A.size());
    bst.find(w);
}
cout << "time for " << bst.size() << " adds and " << 3*A.size() << " searches is " << clock()-t << endl;

char c;
cin >> c;

}

任何和所有的帮助将不胜感激。顺便说一句,我正在使用 PC、Windows 和 Visual Studio Express 2010,用 C++ 编码

4

0 回答 0