views:

18

answers:

1

Hi All,

I am performing file operations (writeToFile) which fetches the data from a xml and writes into a output file(a1.txt).

I am using MS Visual C++ 2008 and in windows XP.

currently i am using this method of writing to output file..

01.ofstreamhdr   OutputFile; 
02./* few other stmts */
03.hdrOutputFile.open(fileName, std::ios::out); 
04.  
05.hdrOutputFile << "#include \"commondata.h\""<< endl ; 
06.hdrOutputFile << "#include \"Commonconfig.h\"" << endl ; 
07.hdrOutputFile << "#include \"commontable.h\"" << endl << endl ; 
08. hdrOutputFile << "#pragma pack(push,1)" << endl ; 
09.hdrOutputFile << "typedef struct \n {" << endl ; 
10./* simliar hdrOutputFiles statements... */..

I have around 250 lines to write.. Is any better way to perform this task.

I want to reduce this hdrOutputFile and use a buffer to do this.

Please guide me how to do that action.

I mean,

buff = "#include \"commontable.h\""  + "typedef struct \n {"  + .......



hdrOutputFile  << buff.

is this way possible?

Thanks

Ramm

+1  A: 

How about:

const char * buffer = 
    "This is one line of text\n"
    "This is the start of another"
    " and this is the end of the same line\n"
    "and so on\n";

hdrOutputFile << buffer;

In both C and C++, string literals like this are automatically concatenated into a single string.

anon