c++ - Random characters in stringstream -
i'm writing program searches files. block of code writes folder name stringstream, preceding "./" can used change directory. changes directory , informs user of change.
stringstream maindir; maindir << "./" << crntmainfile; maindir.str().copy(maindirectory, 260, 0); _chdir(maindirectory); std::cout << maindirectory; std::cout << "main directory changed: " << maindirectory << "\n";
my problem maindirectory
has bunch of characters @ end. i'm assuming has fact it's 260 length array maybe 20 characters in , characters whatever happens occupying unwritten memory. if problem, how fix it?
edit: i've determined crntmainfile
null terminated, terminator lost when it's written maindir
. what's causing this? <<
not write null characters stringstreams? how fix it?
edit: solved problem doing maindir.put(0);
after maindir << "./" << crntmainfile;
manually null terminate string.
std::string::copy
not append null character @ end of copied content.
why don't this
maindir << "./" << crntmainfile ; maindir >> maindirectory; maindir.clear();
Comments
Post a Comment