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

  • SEARCH
  • Home
  • 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 6611445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:58:14+00:00 2026-05-25T19:58:14+00:00

I am new to C++. For a school project I need to make a

  • 0

I am new to C++.
For a school project I need to make a function which will be able to return a string array.

Currently I have this in my header:

Config.h

string[] getVehicles(void);

Config.cpp

string[] Config::getVehicles(){
string test[5];
test[0] = "test0";
test[1] = "test1";
test[2] = "test2";
test[3] = "test3";
test[4] = "test4";

return test;}

Obviously this does not work but that’s the idea of what I am trying to do.
In Java this would be the way to do it. I’ve tried googling my problem but I didn’t come across any answers that were clear to be honest.

  • 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-25T19:58:14+00:00Added an answer on May 25, 2026 at 7:58 pm

    Maybe it is better to use a vector in this case, but this is not a correct answer for the question. The reason why it doesn’t work is that the variable test just exists in the scope of your function.
    So you have to manage the memory on your own. Here is an example:

    string* getNames() {
     string* names = new string[3];
     names[0] = "Simon";
     names[1] = "Peter";
     names[2] = "Dave"; 
    
     return names;
    }
    

    In this case you return a pointer of the position in the heap. All the memory in the heap has to free manually. So it is now your work to delete the memory, if you don’t need it anymore:

    delete[] names;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a school project and i want to dedicate this for New Year,
I am going to start on a new project for my school. I have
Basically I have a school project where I must create a new wave file
So I'm new to Rails (teaching myself as a senior project in high school),
I'm new to rails and have volunteered to help out the local High School
I've created this little quiz for a school project using Java and MySQL. Now
I am fairly new to unit testing. I am in school, and currently taking
I'm currently working on some school project; we are developing a simple RPG, but
I have a school project I'm not supposed to be starting til monday, and
I am trying AJAX for the first time for my school project. I have

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.