Error in loading fragment shader from frag.glsl

this is my fragment shader from shader/frag.glsl

#version 330 core
out vec4 aColor;
void main(){
aColor = vec4(1.0, 0.0, 0.0, 1.0);
}

there are no errors in program compiling but on running the “app.exe” i am getting this error

ERROR::SHADER::COMPILATION_FAILED
ERROR: 0:1: ‘’ : illegal character (0x1)
ERROR: 0:1: ‘’ : illegal non-ASCII character (0xb6)
ERROR: 0:1: ‘’ : illegal non-ASCII character (0xc4)
ERROR: 0:1: ‘’ : illegal character (0x2)
WARNING: 0:1: ‘’ : #version directive missing
ERROR: 0:1: ‘PZ’ : syntax error syntax error

This is my loadShader program:

std::string loadShader(const std::string& path){

std::string result;

std::string line;

std::ifstream myFile(path.c_str());

if (myFile.is_open()) {

    while (std::getline(myFile, line)) {

        result += line + "\\n";

    }

    myFile.close();

} else {

    std::cerr << "Could not read file " << path << ". File does not exist.\\n";

}

return result;

};

this is working fine for vert.glsl .

i also tried to load vert.glsl from file and fragemt shader using

#version 330 core\n”

    "out vec4 aColor;\\n"

    "void main()\\n"

    "{\\n"

    "    aColor = vec4(1.0f, 0.0, 0.0, 1.0);\\n"

    "}\\0";

this combo is working file .

help me where i am wrong in loading fragment shader from frag.glsl .

Based on the location reported in the error messages (at the very start of the file) one guess would be the file might be saved with an unusual text encoding or maybe has a BOM [1] (although the character values in the error don’t look like a BOM sequence to me).

[1] Byte order mark - Wikipedia

Use a debugger. Single step through the code from loadShader to glShaderSource.

I agree with carsten_neumann that this is almost certainly an encoding error. I’ve had very similar errors myself due to text editors deciding to use different encodings. In fact, your driver seems to be better at identifying the issue than mine was; mine just complained about non-existent character locations, but yours is pointing it out:

“illegal non-ASCII character”

As for how to fix this: make sure you’re saving in ASCII (some editors seem to say ANSI), not UTF anything. Also, do not use non-ASCII (non-Latin) characters, as this may trigger your editor to save in UTF-8 or something. You may also want to make your program strip non-ASCII characters from your shaders before sending them to the compiler, but that’s a bit more complicated.