-1
ifstream read("input-1.txt");
int n,u;read >> n;
vector<list<int>> adj_list (n+1);
string delimiter = "->",vertex,list;
size_t pos = 0;int count;
string::size_type sz;
for (int i=0;i<n;i++){
read >> list;
count = 0;
while((pos = list.find(delimiter))!= string::npos){
vertex = list.substr(0,pos);
if (count!=0){
adj_list[i].push_back(stoi (vertex.substr(1,vertex.length()),&sz));
}
list.erase(0,pos+delimiter.length());
count++;
}
}
read >> vertex;
u = stoi (vertex.substr(1,vertex.length()),&sz);
vector<list<int>>::iterator it1 = adj_list.begin();
while(it1!=adj_list.end()){
list<int> new_list = *it1;
list<int>::iterator it2 = new_list.begin();
while(it2!=new_list.end()){
cout << *it2 <<" ";
it2++;
}
cout << endl;
it1++;
}
cout << u << n << "u" << "n";
提供了以下錯誤
even.cpp:37:26: error: template argument 1 is invalid
vector<typename list<int>>::iterator it1 = adj_list.begin();
^
even.cpp:37:26: error: template argument 2 is invalid
even.cpp:37:39: error: qualified-id in declaration before ‘it1’
vector<typename list<int>>::iterator it1 = adj_list.begin();
^
even.cpp:38:8: error: ‘it1’ was not declared in this scope
while(it1!=adj_list.end()){
^
even.cpp:39:8: error: expected primary-expression before ‘int’
list<int> new_list = *it1;
^
even.cpp:40:8: error: expected primary-expression before ‘int’
list<int>::iterator it2 = new_list.begin();
^
even.cpp:41:9: error: ‘it2’ was not declared in this scope
while(it2!=new_list.end()){
^
even.cpp:41:14: error: ‘new_list’ was not declared in this scope
while(it2!=new_list.end()){
矢量是否正確聲明爲int的名單中。但是當它的迭代器被聲明時,它會給出有關模板參數的錯誤。 我只是使用int的而不是任何用戶定義的類,那麼也有我無法理解的錯誤。任何人都可以解決這個問題
您的錯誤與您的代碼不符。那裏有一個額外的'typename'。 – chris