writing to different file names using for loop in C++ visual studio -


i trying write data different files each index. i.e. file name should change datafile0.res datafile99.res depending on index passed.

i using visual c++ 2008.

the code is:

void write_data(int index) {  ofstream coutput;  // first need convert integer index string. not sure if right?  ostringstream temp; temp<<index; std::string s = temp.str(); std::string dir = "c:\my_data\datafile" + s + ".res"; coutput.open(dir); 

when run code, following error appears:

error c2664: 'void std::basic_ofstream<_elem,_traits>::open(const wchar_t ,std::ios_base::openmode,int)' : cannot convert parameter 1 'std::string' 'const wchar_t *' 1>        1>        [ 1>            _elem=char, 1>            _traits=std::char_traits<char> 1>        ] 1>        no user-defined-conversion operator available can perform conversion, or operator cannot called. 

please need help.

thanks in advance

this has nothing stated goal, or concatenation.

std::fstream::open, before c++11, requires const char*, not std::string.

so:

coutput.open(dir.c_str()); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -