#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <string>
using namespace std;
int main(int argc, const char *argv[]) {
ifstream inflie(argv[1]);
int currentLine = 1;
vector<string> words;
map<vector<string>, int> freq;
string line;
while (getline(infile, line)) {
istringstream inputString(line);
currentLine++
string word;
while(inputString >> word){
words.push_back(pair(word, currentLine));
freq[words]++;
}
map<vector<string>, int>::const_iterator iter;
for (iter=freq.begin(); iter != freq.end(); ++iter) {
cout << iter->second << " " << iter->first << endl;
}
return 0;
}
这是我到目前为止所拥有的。当我尝试编译时,它给了我多个错误。请记住,我做的最后一个c ++的东西是在大约两年前的高中。我真的完全不知道自己在做什么。
这是我的错误(这真的很难过):
tabulate.cc: In function `int main(int, const char**)':
tabulate.cc:11: error: `vector' was not declared in this scope
tabulate.cc:11: error: expected primary-expression before '>' token
tabulate.cc:11: error: `words' was not declared in this scope
tabulate.cc:12: error: `vector' cannot appear in a constant-expression
tabulate.cc:12: error: wrong number of template arguments (1, should be 4)
/usr/local/lib/gcc/sparc-sun-solaris2.9/3.4.6/../../../../include/c++/3.4.6/bits/stl_map.h:92: error: provided for `template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
tabulate.cc:12: error: expected unqualified-id before ',' token
tabulate.cc:12: error: expected unqualified-id before "int"
tabulate.cc:14: error: `infile' was not declared in this scope
tabulate.cc:15: error: variable `std::istringstream inputString' has initializer but incomplete type
tabulate.cc:17: error: expected `;' before "string"
tabulate.cc:18: error: `word' was not declared in this scope
tabulate.cc:19: error: missing template arguments before '(' token
tabulate.cc:20: error: `freq' was not declared in this scope
tabulate.cc:20: warning: unused variable 'freq'
tabulate.cc:22: error: `vector' cannot appear in a constant-expression
tabulate.cc:22: error: wrong number of template arguments (1, should be 4)
/usr/local/lib/gcc/sparc-sun-solaris2.9/3.4.6/../../../../include/c++/3.4.6/bits/stl_map.h:92: error: provided for `template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
tabulate.cc:22: error: expected unqualified-id before ',' token
tabulate.cc:22: error: expected unqualified-id before "int"
tabulate.cc:23: error: `iter' was not declared in this scope
tabulate.cc:23: error: `freq' was not declared in this scope
tabulate.cc:14: warning: unused variable 'infile'
tabulate.cc:27: error: expected `}' at end of input