LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   opening files with strings for file names (https://www.linuxquestions.org/questions/programming-9/opening-files-with-strings-for-file-names-114445/)

veilig 11-10-2003 10:47 AM

opening files with strings for file names
 
alright, I have 2 strings, I appended the second string the first string and now I want open a file which is the first strings name

s1 = myfile.
s2 = 2

s1+=s2
s1 is now myfile.2

how can I use s1 to open that file?

when I type:
fstream Fin( s1, ios::in );

I'm getting errors that I can't do this with the string as the file name.

any ideas?

LogicG8 11-10-2003 10:54 AM

Well you are using the string library correct?

fstream I believe expects a character array.
try the s1.c_str() method

veilig 11-10-2003 11:05 AM

yeah I am using the string library,

I tried using

fstream Fin( s1.c_str(), ios::in );

like you suggested...and it compiled, but my
if ( ! Fin )...

error checking, get spitting out my error message, so it seems like it's still not opening?

veilig 11-10-2003 11:05 AM

got it to work, thanks

LogicG8 11-10-2003 11:19 AM

Glad you got it to work,
but next time you are having a
problem I have some advice

Put more detail in the post
like what language, and libraries you are using.
variable declarations are also helpful.
My advice was just a guess at what could be wrong.


All times are GMT -5. The time now is 10:04 AM.