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 784779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:46:02+00:00 2026-05-14T20:46:02+00:00

So I am a first year computer science student, for on of my final

  • 0

So I am a first year computer science student, for on of my final projects, I need to write a program that takes a vector of strings, and applies various functions to these. Unfortunately, I am really confused on how to use pointer to pass the vector from function to function. Below is some sample code to give an idea of what I am talking about. I also get an error message when I try to deference any pointer.

thanks.

#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;

vector<string>::pointer function_1(vector<string>::pointer ptr);
void function_2(vector<string>::pointer ptr);


int main()
{
   vector<string>::pointer ptr;
   vector<string> svector;

   ptr = &svector[0];

   function_1(ptr);
   function_2(ptr);
}

vector<string>::pointer function_1(vector<string>::pointer ptr)
{
   string line;

   for(int i = 0; i < 10; i++)
   {
       cout << "enter some input ! \n"; // i need to be able to pass a reference of the vector
       getline(cin, line);              // through various functions, and have the results 
      *ptr.pushback(line);             // reflectedin main(). But I cannot use member functions  
   }                                      // of vector with a deferenced pointer.

   return(ptr);
 }

 void function_2(vector<string>::pointer ptr)
 {
    for(int i = 0; i < 10; i++)
    {
       cout << *ptr[i] << endl;
    }
 }
  • 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-05-14T20:46:03+00:00Added an answer on May 14, 2026 at 8:46 pm

    std::vector<T>::pointer is not std::vector<T>*, it is T*.

    Don’t worry about using pointers; just use references, e.g.,

    void function_1(std::vector<string>& vec) { /* ... */ }
    

    function_2, which does not modify the vector, should take a const reference:

    void function_2(const std::vector<string>& vec) { /* ... */ }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a first year computer science student. We are currently programming in java and
I'm a first year computer science student. I am trying to teach myself hash
I'm a first year computer science student, having returned several years after finishing high
I'm a first year computer science student having a problem with part of an
I’m reading towards M.Sc. in Computer Science and just completed first year of the
I am teaching a course Introduction to Computer Programming to the first year math
The assignment at my first year uni computing course says my program should read
When I first started to program in C# last year, I immediately looked for
I'm in my first year of Computer Sciences and I have to design a
I am a first year Comp. Sci. student and am looking for the best

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.