Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

C++ code to wright a bat file


ghost's Avatar
0 0

Can someone tell me how to do a program that make a bat file and wright some code in it.

Please make a little example of code here in the Thread.

//wildzor


hust921's Avatar
Member
0 0
#include <fstream>
using namespace std;

int main()
{
  ofstream Fil("something.bat", ios::app);
  Fil<<"@echo off"<<endl;
  Fil<<"echo Hallo,world"<<endl;
  Fil<<"pause"<<endl;
  Fil.close();
  return 0;
}

This code will make a batch file look like this:

@echo off
echo Hello, world
pause

hust921B)


ghost's Avatar
0 0

ok thanx so mutch :)


ghost's Avatar
0 0

You also could skip the batch file. if all your trying to do is execute commands try system(commandhere); example:

int main() { system("ping nsa.gov"); }

enjoy


ghost's Avatar
0 0

read my tutorial on c++ system commands