Apr 24, 2010 at 10:48pm UTC
why don't you do something like:
global
string file_for_import;
locals
char temp[20];
scanf("%s",temp);
file_for_import=temp;
file_for_import+="jjj";
global
ofstream outputFile(file_for_import.c_str(),ios::binary);
but it would be better if you told us what exactly is it that you want to do...
Last edited on Apr 24, 2010 at 10:49pm UTC
Apr 25, 2010 at 4:16am UTC
In outputFile write many modules. So outputFile must be global. But the name of outputFile consist from different parts. So in main function file_for_import must be constructing.
Then how can i have global outputFile?
Apr 25, 2010 at 10:57am UTC
Ah, you see, when you have an ofstream object it's not necessary to associate a file with it upon instantiation.
Just declare your ofstream object in global scope like:
ofstream outputFile;
Then you can later do something like:
outputFile.open(file_for_import.c_str(),ios::binary);
(and file_for_import can be local)
And when you finish with it do something like:
outputFile.close();
and then open another file.
Last edited on Apr 25, 2010 at 11:05am UTC
Apr 25, 2010 at 8:31pm UTC
Ok, i just open my pc. I will try with this piece of code.
Many thanh's, and good day.
Jim.
Apr 26, 2010 at 1:25am UTC
use variable static
may be can help