The push_back method of the std::vector isn't putting the second console input in the v[1] slot, it keeps overwriting it in the v[0]
I tried to search for other answers to this but the code and answer is too complicated for me to follow, im trying to keep it simple (But i tried using pointers, just got a bunch of errors)
My Method:
vector<string> createtable(std::vector<std::string> v, std::string insertedstr) {
std::vector<std::string> vcreate;
vcreate.push_back(insertedstr + " ");
return vcreate;
}
Main:
int main()
{
int option;
std::string insertedstr;
std::vector<std::string> v;
cin >> insertedstr;
v = createtable(v, insertedstr);
for (int i = 0; i <=v.size(); i++) {
cout << v[i] << endl;
}
cin >> insertedstr;
v = createtable(v, insertedstr);
for (int i = 0; i <= v.size(); i++) {
cout << v[i] << endl;
}
return 0;
}
Edit: I want to eventually write a menu for this so I want to have an infinite amount of push_backs, so just calling v.push_back in the main won't work for me
Would be great if someone could help.