I'd hazard a guess that the GLSL parser has problems reading certain code fragments when they're all munged together: since no newline character appears inside of the quoted strings, the expression used to initialize 'shaderdata' evaluates to a single line of text.
Try using C++11 raw string literals (or, if you're stuck with an older compiler, place a \n on the end of each string):
const std::string shaderdata = R"(
uniform sampler2D objtexture;
uniform sampler2D fogtexture;
uniform sampler2D lighttexture;
void main()
{
// Load textures into pixels
vec4 objpixel = texture2D(objtexture, gl_TexCoord[0].xy);
vec4 fogpixel = texture2D(fogtexture, gl_TexCoord[0].xy);
vec4 lightpixel = texture2D(lighttexture, gl_TexCoord[0].xy);
// Draw objects if a lighttexture pixel is fully-transparent
// Otherwise, hide objects behind fog
bool changealpha = bool(ceil(lightpixel.a));
objpixel = vec4((lightpixel.rgb) * float(changealpha) + objpixel.rgb * float(!changealpha), lightpixel.a * float(changealpha) + objpixel.a * float(!changealpha));
objpixel = mix(objpixel, fogpixel, fogpixel.a);
gl_FragColor = objpixel;
})";
Raw string literals are "new" (in C++11).
As for normal literals: Just look at the following snippet. All the strings are essentially the same, since they're concatenated and the line breaks are outside the strings:
const char *a = "Hello World!";
const char *b = "Hello"" ""World!";
const char *c = "Hello"
" "
"World!";