读书人

生成BAT文件的代码如何写

发布时间: 2012-05-06 16:15:43 作者: rapoo

生成BAT文件的代码怎么写?
代人发帖求助,他用VS2005写一个vc++的软件,其中一部要生成一个.bat的文件,这部分代码怎么写啊?我没写过C++的代码,所以特来求教。谢谢各位了

[解决办法]
把批处理文件当作文本文件来写就行了。

C/C++ code
#include <iostream>#include <fstream>using namespace std;int main () {  ofstream myfile ("example.bat");  if (myfile.is_open())  {  myfile << "@ECHO OFF\r\n"; myfile << "ECHO data1\r\n"; myfile << "ECHO ok,gooooogoooooooooo\r\n";myfile << "PAUSE\r\n";  myfile.close();  }  else cout << "Unable to open file";  return 0;} 

读书人网 >VC

热点推荐