System() no suitable conversion C++ -


i have 2 lists file names.

std::list<std::string> userfontlist; std::list<std::string>::iterator it; std::list<std::string> caatfontlist; std::list<std::string>::iterator it2; std::list<std::string> doesnthavelist; 

and want compare 2 lists, , delete value matches. every seems fine until add "del /f /q /a" y.c_string().

for (it = userfontlist.begin(); !=userfontlist.end(); ++it){     for(it2 = caatfontlist.begin();it2 !=caatfontlist.end();++it2){         if(*it==*it2){             string y = *it;             string k = y.c_str();             string = "del /f /q /a " + k;             system(a);          }     }  } 

system(a) says have "no suitable conversion function std string const char * exists". if put whole thing 1 string works, not when concatenate string , y.c_str(). have had no luck trying convert std::string const *char, not sure if helps.

exactly says, there's no version of system() understands std::string , std::string can't freely converted const char * (which system() understand), because std::string may go away in ways don't make sense in general case.

you can explicitly convert std::string const char * easily, though: std::string::c_str, write last line as

system(a.c_str()); 

be aware returned const char *'s lifetime tied string came from, once goes out of scope, pointer becomes invalid. case fine time use it, though, since system() won't "hold on" pointer past own return.


Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -