Computer Hope
Microsoft => Microsoft DOS => Topic started by: Teroro on October 28, 2021, 02:02:07 PM
-
So. I have a string that I create within a file and I want to put spaces,new lines and add some input in the code but it doesn't work.
I tried putting ""
between the text as I saw online but it doesn't work. And the new lines I didn't found on the internet.
Im trying to create a file with this code in it and this is how I got it to even create the file.
set /p CPPFileName=
echo ^#include^<fstream^>usingnamespacestd^;ifstreamfin(^"^")^;ofstreafout(^"^")^;int main^(^)^{inta^,b^;fin^>^>a^>^>b^;fout^<^<a^*b^;^} > "%CPPFileName%"
And this is the output
#include<fstream>usingnamespacestd;ifstreamfin("");ofstreafout("");int main(){inta,b;fin>>a>>b;fout<<a*b;}
But I want this to be the output using Spaces And New lines
#include<fstream>
usingnamespace std;
ifstream fin("");
ofstreaf out("");
int main()
{
int a,b;
fin>>a>>b;
fout<<a*b;
}
And also about Inserting text.
I have 2 Inputs and the name of the strings are File1Name
and File2Name
Is there a way I could add these strings in the code string I want to output?
Like ^#include^<fstream^>usingnamespacestd^;ifstreamfin(^"%File1Name%^")^;ofstreafout(^"%File2Name%^")^;int main^(^)^{inta^,b^;fin^>^>a^>^>b^;fout^<^<a^*b^;^}
If you could help me it would be awesome!
-
Not sure why you have all that additional escaping. To resolve your initial problem you can do this.
set /p CPPFileName=
(
echo #include^<fstream^>
echo usingnamespace std;
echo ifstream fin(""^);
echo ofstreaf out(""^);
echo int main(^)
echo {
echo int a,b;
echo fin^>^>a^>^>b;
echo fout^<^<a*b;
echo }
)> "%CPPFileName%"
I am not sure I am understanding your second issue. I don't see any code where your are assigning any variables named File1Name or File2Name so I am not sure if you want the values of the variables or you literally want to output %File1Name%.
-
Thanks again for the help!
I got it to work after playing with the strings for some more but thanks anyways