printf - C++ snprintf "cannot pass objects of non-POD type" -
i trying write program has config , key file. config file reads ever inputted key file, parses , executes key values needed.
i getting error: warning: cannot pass objects of non-pod type ‘struct std::string’ through ‘...’; call abort @ runtime.
i receiving error on line:
snprintf(command, 256, "tar -xvzf %s %s", destination, source); system(command);
more of code try , better explain:
std::string source = cfg.getvalueofkey<std::string>("source"); std::string destination = cfg.getvalueofkey<std::string>("destination"); int duration = cfg.getvalueofkey<int>("duration"); int count, placeholder, placeholderadvanced; count = 1; char command[256]; snprintf(command, 256, "tar -xvzf %s %s", destination, source); system(command); //creates folder 1. snprintf(command, 256, "mkdir %i", count); system(command); //removes last folder in group. snprintf(command, 256, "rm -rf %i", duration); system(command);
any suggestions on doing wrong, or should looking?
thank you!
snprintf
knows nothing std::string
. in case, expects null-terminated c strings, is, pointers char
beginning of sequence of characters ends in null character. can obtain underlying null terminated string held std::string
object via c_str()
method:
snprintf(command, 256, "tar -xvzf %s %s", destination.c_str(), source.c_str());
Comments
Post a Comment