So I am having an issue using basename for one of my programming assignments for school
I have tried getting a simplier version of it working -- I got it working however, still confused exactly what I am supposed to do in this case
// $Id: util.cpp,v 1.1 2016-06-14 18:19:17-07 - - $
#include <libgen.h>
#include <cstring>
using namespace std;
#include "util.h"
ydc_exn::ydc_exn (const string& what): runtime_error (what) {
}
string exec::execname_; // Must be initialized from main().
int exec::status_ = EXIT_SUCCESS;
void exec::execname (const string& argv0) {
execname_ = basename (argv0.c_str());
cout << boolalpha;
cerr << boolalpha;
DEBUGF ('Y', "execname = " << execname_);
}
void exec::status (int new_status) {
new_status &= 0xFF;
if (status_ < new_status) status_ = new_status;
}
ostream& note() {
return cerr << exec::execname() << ": ";
}
ostream& error() {
exec::status (EXIT_FAILURE);
return note();
}
Just trying to get the code to compile --- my error message in c++ is: ' util.cpp:15:16: error: no matching function for call to 'basename' execname_ = basename (argv0.c_str()); ^~~~~~~~ /usr/include/libgen.h:40:7: note: candidate function not viable: 1st argument ('const std::__1::basic_string, std::__1::allocator
::value_type *' (aka 'const char *')) would lose const qualifier char *basename(char *); ^ 1 error generated. make: *** [util.o] Error 1'
Aucun commentaire:
Enregistrer un commentaire