我的 void print 函数无法打印出这个向量。我不太确定“std::allocator”在说什么。我收到以下错误:
st1.cpp: In function ‘void Print(std::vector<int, std::allocator<int> >)’:
st1.cpp:51: error: declaration of ‘std::vector<int, std::allocator<int> > v’ shadows a parameter
这是文件:
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
void Initialize();
void Print();
int main()
{
stack<string> s1, s2;
s1.push("b");
s2.push("a");
if (s1.top() == s2.top())
{
cout << "s1 == s2" << endl;
}
else if (s1.top() < s2.top())
{
cout << "s1 < s2" << endl;
}
else if (s2.top() < s1.top())
{
cout << "s2 < s1" << endl;
}
else
{
return 0;
}
vector<int> v;
Initialize();
Print();
}
void Initialize(vector<int> v)
{
int input;
cout << "Enter your numbers to be evaluated: " << endl;
while(input != -1){
cin >> input;
v.push_back(input);
//write_vector(v);
}
}
void Print (vector<int> v){
vector<int> v;
for (int i=0; i<v.size();i++){
cout << v[i] << endl;
}
}
我只想将 v 打印到屏幕上。有什么帮助吗?