LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   creating a file with la long name on C++ (https://www.linuxquestions.org/questions/programming-9/creating-a-file-with-la-long-name-on-c-201474/)

poeta_boy 07-05-2004 05:15 PM

creating a file with la long name on C++
 
Hi there:

I wanna create a file in C++ with a long name, maybe:

C:\documentation\PackageFrameWriter\PackageFrameWriter.html

so I put it as a char*

string file("C:\documentation\PackageFrameWriter\PackageFrameWriter.html") ;

ofstream fileHandler(file.c_str(), ios::out);

but it keeps telling me there's an error creating the file:


if(!fileHandler)
{
cout << "error" << endl;
return;
}


when I got desperated, I changed the file string for something like



file = "hello.html"



And it worked correctly... my guess is that I cannot create a file with such a long name right? is it true? is there a way around?

thanks for you time!

Poeta

Dark_Helmet 07-05-2004 05:27 PM

First thing, your string is probably not quite right. Every use of a backslash ought to be "escaped". For instance:

string file("C:\\documentation\\PackageFrameWriter\\PackageFrameWriter.html");

However, I don't know whether the "string" data type handles that for you (I don't use C++ much at all).

Second, make sure the parent directories exist. If not, you'll need to create them.

poeta_boy 07-05-2004 06:17 PM

hello:

thanks for the quick response.... the problems was with the directory, I didn't create them... actually the string does the work quite ok, and it doesn't need to have scape chars...

Thanks a lot!


All times are GMT -5. The time now is 05:29 PM.