So, I started messing around with a .bat file and started learning how to use variables, user input, show text using the commands: echo,set,etc.
And I noticed I can create files with the command: echo > (File name) Which was really intresting but I ran into a problem.
When creating a file you can do: echo "Text in it" > (File name) and I tried putting a CPP script in it but it doesn't seem to work. Can anyone tell me why?
I tried putting it into a string:
set Code=#include<fstream>usingnamespacestd;ifstreamfin("");ofstreamfout("");int main(){inta,b;fin>>a>>b;fout<<a*b;
I tried directly applying it:
echo #include<fstream>usingnamespacestd;ifstreamfin("");ofstreamfout("");int main(){inta,b;fin>>a>>b;fout<<a*b; > "%CPPFileName%"
Can anyone help me with this?
Heres the full code:
@echo off
echo In File name:
set /p File1Name=
echo 2 Variables:
set /p Variables=
echo %Variables% > "%File1Name%"
echo Out File name:
set /p File2Name=
echo 0 > "%File2Name%"
echo CPP File name:
set /p CPPFileName=
set Code=#include<fstream>usingnamespacestd;ifstreamfin("");ofstreamfout("");int main(){inta,b;fin>>a>>b;fout<<a*b;
echo #include<fstream>usingnamespacestd;ifstreamfin("");ofstreamfout("");int main(){inta,b;fin>>a>>b;fout<<a*b; > "%CPPFileName%"