I have a strange bug in vs2008.

ostream open fails when called in the following manner:

ofstream filestr;
filestr.open((filename.c_str()),ios::in|ios::out);

when called like this it works without a hitch:

ofstream filestr;
filestr.open("blahblah.txt",ios::in|ios::out);

Any ideas?

Thanks

For me, it is working with that ...

filestr.open( filename.c_str() );

>Any ideas?
Remove ios::in :)

EDIT::
I usually open files like this if I want to open them in text mode:

string fn = "test.txt";
ofstream fout;
fout.open( fn.c_str() );

(I also used a string like you did)

Thanks for the replies, I forgot to mention that the string is created dynamically using ostringstream

int limits;
....


while (limits < MAX_NUM)
{
...
ostring << "blah_" << limits << ".txt" <<endl;
filename = ostring.str();
...
limits++;
}

I dug in and saw that mbstowcs_s that attempts convert multi bite chars to wide fails.
Why this conversion is needed I do not know... And I would be happy to avoid it... :)

>I dug in and saw that mbstowcs_s that attempts convert multi bite chars to wide fails.
Why this conversion is needed I do not know... And I would be happy to avoid it...

What is your code intended to do?

This part of the code needs to create files each containing text permutations, the first file contains permutations of with the length of one. The second file contains permutations with the length of two based on the permutations created in the first file. The permutations in the third file are of length 3 and are based on the permutations created in the second file and so on...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.