c++ - QT ofstream use variable as a path name -
i'm trying make function takes qstring int. convert qstring variable filename ofstream, take integer , place file. far have managed take constant filename such "filename.dat" , write variable it. when try use qstring :
void write(const char what,int a){ std::ofstream writefile; writefile.open("bin\\" + what); writefile << a; writefile.close(); }
i error
void write(const char,int)': cannot convert argument 1 'const char [5]' 'const char
this function calls write();
void server::on_dial_valuechanged(int value) { write("dial.dat",value); }
when use "bin\dial.dat" instead of combining "bin\" string works fine. ofstream.open(); uses "const char*".
i've tried filetypes may not match description
the question is- have idea how combine "bin\" , qstring , make work ofstream? i've spend lot of time googling still can't make work. thanks! suggestions more welcome
void write(const char what,int a)
wrong pass 1 char function should have void write(const char* what,int a)
pass pointer cstring beginning.
you want concat 2 cstrings , in c++ can't in other languages can use std::string want.
try this
#include <string> void write(const char* what,int a){ std::ofstream writefile; std::string filename("bin\\"); filename+=what; writefile.open(filename.c_str()); writefile << a; writefile.close(); }
Comments
Post a Comment