开发者

Any Alternate way for writing to a file other than ofstream

开发者 https://www.devze.com 2023-01-04 11:29 出处:网络
I am performing file operations (writeToFile) which fetches the data from a xml and writes into a output file(a1.txt).

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.
开发者_如何学Go

is this way possible?

Thanks

Ramm


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消