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

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -