Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9223117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:59:51+00:00 2026-06-18T03:59:51+00:00

I am having trouble with my void print function to print out this vector.

  • 0

I am having trouble with my void print function to print out this vector. I’m not quite sure what it is talking about with “std::allocator. I get these errors:

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

Here is the file:

#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;
}
}

I just want to print v out to the screen. Any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:59:52+00:00Added an answer on June 18, 2026 at 3:59 am

    Your function declaration and definition are not consistent, you want to generate vector from Initialize, you can do:

    void Initialize(vector<int>& v);
    

    To print vector:

    void Print(const vector<int>& v);
    

    Now you call:

    vector<int> v;
    Initialize(v);
    Print(v);
    

    Don’t forget to change function definition of Initialize, Print to match the new signature I provided above.
    Also you are redefining a local variable v which shadows function parameter, you just need to comment out that line, also pass vector by const ref:

    void Print (const vector<int>& v){
      //vector<int> v;
      for (int i=0; i<v.size();i++){
        cout << v[i] << endl;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble with this code. I am trying to write a function
I'm teaching myself about structures in C, and am having trouble compiling this code:
I'm having trouble with a method to read my plist: @synthesize data //NSMutableArray -(void)readPlist{
I'm having trouble loading a custom font. .m file: - (void)viewDidLoad { [label setFont:[UIFont
Having trouble with each function... Will try to explain by example... In my code,
Having trouble framing this assertion in Rspec for my rails app. A User has
I am having trouble with this error I am receiving whenever I run my
I'm having troubles with method1 below. It gives the warning prototyped function not called
I'm having trouble figuring out what's wrong with my program. I've constructed it with
so I'm having trouble figuring out where I should be implementing the type cast

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.