c++ - std::stringstream.str() outputs garbage -


i need save bunch of image files numbered indices. trying construct these filenames using stringstream. however, stringstream.str() not seem return filename, rather returns garbage.

here code:

std::stringstream filename; filename << filepath << fileindex << ".png"; bool ret = imwrite(filename.str(),frame, compression_params); fileindex++; printf("wrote %s\n", filename.str()); 

here output 1 execution:

wrote ╠±0 wrote ╠±0 wrote ╠±0 wrote ╠±0 

here output execution:

wrote ░‗v wrote ░‗v wrote ░‗v wrote ░‗v 

any suggestions? imwrite opencv function, , have [code]using namespace cv;[/code] @ top of file - there interference between opencv , std?

you can't pass non-pod type std::string c-style variadic function printf.

you use c++ output:

std::cout << "wrote " << filename.str() << '\n'; 

or, if old-school weirdness, extract c-style string c-style output:

printf("write %s\n", filename.str().c_str()); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -