1.

Solve : String Spaces,New Lines and Inserting Text?

Answer»

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 Code: [Select]"" 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.
Code: [Select]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
Code: [Select]#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
Code: [Select]#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 Code: [Select]File1Name and Code: [Select]File2Name Is there a way I could add these strings in the code string I want to output?
Like Code: [Select]^#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.

Code: [Select]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



Discussion

No Comment Found