c++ - std::make_pair <const char*,int > -
i have function called of 'main' method same arguments main called (int main (int argc, char* argv[]))
std::pair<const char *, int> mtd1 (int argc, char * argv[]){ . . . }
since argv[1] pointer string (assume atleast 1 program argument except argv[0]), not constant pointer, still possible (not error) pass argv[1] in return statement inside mtd1
return std::make_pair <argv[1],99999 >
or need inside mtd1
method
const char *abc = arg[1]
before returning
return std::make_pair (abc,99999 ) <- edited
how doing safe way?
std::pair<std::string, int> mtd1 (int argc, char * argv[]) { . . . }
and
return std::make_pair (std::string(argv[1]),99999);
if insist on returning std::pair<char*,int>
, should work:
return std::make_pair (argv[1],99999);
Comments
Post a Comment