I'm trying to develop a program that, in case 2, after an array has been "filled" it adds another space so you are able to add another value to your original array. I tried my best but failed miserably. I cannot use std::copy to just copy the array and add it to a new one with more space in it. Any help is appreciated, thanks!
#include <iostream>
#include <string>
using namespace std;
void stampa (string x[], int q){ //Cout all inserted names
int i;
cout<<"Your names are: "<<endl;
for (i=0; i<q; i++){
cout<<x[i]<<endl;
}
}
void carica(string x[], int q){ //Function to insert the names
int i;
for(i=0; i<q; i++){
cout<<"Insert the "<<i+1<<" name:"<<endl;
cin>>x[i];
}
}
void controllo (int &x){ //Error if a negative number is inserted
while (x<=0) {cout<<"Error! Insert a positive number:"<<endl;
cin>>x;
}
}
int main(){
int scelta, n;
string nome;
bool exit=false;
cout<<"How many names do you want to enter?"<<endl;
cin>>n;
controllo(n);
string a[n];
carica(a,n);
do{
system("cls");
cout<<"1) Print your names"<<endl;
cout<<"2) Insert a new name"<<endl;
cout<<"3) Exit"<<endl<<endl;
cin>>scelta;
switch (scelta){
case 1:
stampa(a,n);
system("pause");
break;
case 2:
cout << "Enter new name to insert: " << endl;
cout<<"Done!"<<endl;
system("pause");
break;
case 3:
exit=true;
cout<<"Goodbye!"<<endl;
break;
}
}while (!exit);
system("pause");
}