But, what if I can't do an escape sequence. What if I'm in a situation where I absolutely need the code to be in the way it was before this guy got it fixed, just working?
and will probably complain that you've made a failed attempt to use a variable called hello (e.g. undeclared identifier, missing operator, ...).
The \ tells the compiler that the next character in the string needs to be treated specially. In the case of \", it says this " is an actual " (part of the string) rather than the end of the string.
Other languages have their own way of solving this problem (e.g. VB does it by doubling the quote character to mean an actual quote)
But, what if I can't do an escape sequence. What if I'm in a situation where I absolutely need the code to be in the way it was before this guy got it fixed, just working?
Such a situation is impossible. No sense in worrying about "what ifs" that will never happen.
@James Burnby & Galik: Thanks, but James' method didn't work & Galik's is impossible for the same reason escape sequences are. (Not to be rude.)
Basically, the reason I need to do something like this is I'm essentially trying to enclose HTML in printf. The problem is, this is the code: printf("<html><body><h1><a accesskey="Y" href="/home/master260/Downloads/Project Is This a Bad Game/Actual Work/HTML 2.html" target="_blank"><img src="/home/master260/Downloads/Project Is This a Bad Game/Actual Work/Start Menu.png" border="0" alt="Welcome to ITABG!"></a></h1></body></html>");
Do I take it you that you want to literally include a bit of HTML in your cpp? As in
#include "example.html"
Because if you are cutting and pasting the HTML into you code, there's nothing to stop you editing the string so it's correctly escaped. And if you're loading the HTML from a file, it's a non-issue (the loaded characters will be whatever's in the file).
If so, write a script to escape the HTML file, writing the result to the temporary file, and then include that.
Unless I am missing something here there, I still don't see any reason you can just use escape sequences:
1 2 3 4 5 6 7
printf(
"%s",
"<html><body><h1><a accesskey=\"Y\" ""href=\"/home/master260/Downloads/Project Is This a Bad Game/Actual Work/HTML 2.html\" ""target=\" blank\"><img src=\"/home/master260/Downloads/Project Is This a Bad Game/Actual Work/Start Menu.png\" ""border=\"0\" alt=\"Welcome to ITABG!\"></a></h1></body></html>"
);
BTW, be careful with the format string for printf() -- it is better to use "%s" and pass the text you want as argument to that.
The problem is, I'd imagine that'd interfere with the HTML. You see:
printf("<html><body><h1> & </h1></body></html>"); are C++ code.
<a accesskey="Y" href="/home/master260/Downloads/Project Is This a Bad Game/Actual Work/HTML 2.html" target="_blank"><img src="/home/master260/Downloads/Project Is This a Bad Game/Actual Work/Start Menu.png" border="0" alt="Welcome to ITABG!"></a is HTML.
Hmm, well this is odd. I've been using Qt Creator & it seems to always output to something that just says, "Hello World!" I've concluded it does that whenever it doesn't have any errors, but it didn't recognize what you did, specifically, as if you hadn't input any code besides the default code in something made with Qt Creator.