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? |
Well you are using the string library correct?
fstream I believe expects a character array. try the s1.c_str() method |
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? |
got it to work, thanks
|
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. |