How do i put programming partheses?

How do i put programming partheses? I mean i am writing a programe that wrirtes PHP code in a file using fstream.However im having a hard time doing that.Like this piece of code.

Code i have now

  PhpLog << "$handle = fopen" << " ( log.txt" , "a ;)";

Code im trying out
 PhpLog << "$handle = fopen" << " ( " << ""log.txt"" , "a ;)";

What the PHP code looks like now.

$handle = fopen ( log.txt , a );

What I want the PHP code looks like now.

$handle = fopen("log.txt", "a");

Any help guys?

You have to escape the quotation marks.

PhpLog << "$handle = fopen (\"log.txt\" , \"a\"); ";

Thanks it worked!.

But im also having problems with my other lines of code.

Codes im trying out

PhpLog << "fwrite($handle, " << "/" << "\r\" << "/" << "\n\" << ";)";

PhpLog << "fwrite($handle, " << "/r" << "n)/" << ";";

What I want the PHP code to look like.

fwrite($handle, "\r\n");

fwrite($handle, "\r\n");

I never thought writing PHP code to C++ would be tricky xD.I appreciate the help.
Last edited on
In strings, the '\' character is reserved as an escape character. Therefore, to use characters like quotation marks or the backslash itself, you must "escape it" as Anon has mentioned.

For example, to write
, you would write out:
cout << "\"\\r\\n\"";

Notice how there are four characters being escaped.
//In summary:
cout << "\""; //displays "
cout << "\\"; //displays \ 
C++11 has raw string literals, use them in situations of this kind.
Thanks Daleth that summary really helped.Also the link that JLBorges gave had really helpful information.My program managed to compile with no errors.
Topic archived. No new replies allowed.