2010-06-18 72 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++中,字符串字面这样会自动连接成一个字符串。

相关问题