Monday, July 27, 2009

I want to open a file in c++(actually creating it) with the name that is defined by the user how can I do so?

fopen does not work because it takes a const string as the first argument.


thanks in advance!

I want to open a file in c++(actually creating it) with the name that is defined by the user how can I do so?
EASY





# include %26lt;iostream.h%26gt;


#include %26lt;conio.h%26gt;


#include %26lt;fstream.h%26gt;





int main()


{


char Filename[50];


gets(Filename);


ofstream file;


file.open("Filename");


file%26lt;%26lt;"THIS IS A TEXT";


file.close();


return 0;


}





THIS IS THE CODE


I WORKED ON C++ A FAR BACK





BUT I HADN'T FORGOT C++


WE BOTH (c++ and me ) HAVE A DEEP RELATIONSHIP





but anyway can u tell me for what purpose u need this code, freely reply me .....





OK


ENJOY
Reply:To complete that previous answer:


const_cast%26lt;char*%26gt;
Reply:C sharp rules!
Reply:You can cast your input string to a const string in the fopen parameters.


No comments:

Post a Comment