So i have a program i am writing,and i have come to problem. I want to be able to pass a set of three strings into a function, which should then take them and add them to a Vector. All good so far, now is where my problem develops, how do i get that vector out of the function. I want to able to able to have a separate function with in the same class, that will print all three items in the vector. i want it to be a separate Function so i can call when i want
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;
class ship
{
char Name[256];
public:
void setName(char *nam)
{
strcpy(Name, nam);
cout << Name;
}
vector<string> inven(string frt, string sec, string thir)
{
vector<string> inventor;
inventor.push_back (frt);
inventor.push_back (sec);
inventor.push_back (thir);
cout << inventor[0];
return inventor;
}
};
int main()
{
char shipcall[256];
ship player;
vector<string> main_inventor;
cout << "welcome to space \n";
string frt = "Credits";
string sec = "cargo";
string thir = "Armaments";
cout << " Name your ship\n";
cin.get(shipcall,156);
player.setName(shipcall);
player.inven(frt, sec,thir);
cout << main_inventor[0];
system ("pause");
return 0;
}