相信你和我一样也喜欢随时鼓捣些有趣的代码,不然你也不会找到这个文档,这些代码经过编译连接之后会形成一个可以自动打开记事本并向记事本中录入相关文字,在这中间嵌入的是VBS代码,我个人对BVS代码是有某种特殊感情的,特别喜欢这个代码。
不多说,先看代码:
//outfile.cpp--writing to a file
#include<iostream>
#include<fstream>
int main(){
using namespace std;
char automobile[]={"on error resume next\nset WshShell= WScript.CreateObject(\"WScript.Shell\")\nWshShell.Run\"notepad.exe\"\nWScript.Sleep 2000\nWshShell.SendKeys\"hello world!\"\n"};
ofstream outFile;//create object for output
outFile.open("carinfo.vbs");//associate with a file
cout.precision(2);
cout.setf(ios_base::showpoint);
outFile<<fixed;
outFile.precision(2);
outFile.setf(ios_base::showpoint);
outFile<<automobile<<endl;
outFile.close();//done with file
system("carinfo.vbs");
return0;
}。