2010-06-18 71 views
0

我正在執行文件操作(writeToFile),它從XML讀取數據並寫入輸出文件(a1.txt)。任何替代方式寫入文件以外的文件

我正在使用MS Visual C++ 2008和Windows XP中。

目前我使用寫入到輸出文件的這個方法..

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... */.. 

我有大約250線寫..是執行此任務的任何更好的辦法。

我想減少此hdrOutputFile並使用緩衝區來執行此操作。

請指導我如何做到這一點。

我的意思是,

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



hdrOutputFile << buff. 

是這樣,可能嗎?

感謝

拉姆

+0

一個地方要開始將格式化您的代碼,以便更容易閱讀:p – 2010-06-18 14:33:00

回答

1

如何:

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; 

在C和C++中,字符串字面這樣會自動連接成一個字符串。

相關問題