I'm trying to copy argv to a new vector of strings which I want it to be global so I can use it in another function:
here i'm using this line to copy argv : std::vector<std::string> args( argv, argv + argc );
std::vector< std::string> args; //global
int main(int argc, char *argv[]){
if(argc <2 ||argc-2 != atoi(argv[1])){
cout << "illegal arguments" << endl;
return -1;
}
std::vector<std::string> args( argv, argv + argc ); // copying here
// some more code in the main (works fine)
}
And here i'm using it (another function in the same file):
void* ATM_Threads(void* atm_id){
int* id=(int*) atm_id;
stringstream buff;
//buff <<"ATM_"<<*id<<"_input_file.txt"; // using this line instead of the next one works just fine
buff<<args[*id+1]; //here i'm using the vector which gives me core dumped SF
}
But im getting segmentation fault.. any idea why?