I am writing a method which requires reading a file and putting all its contents into a string variable.
This is what I have tried:
unsigned int ShaderHandler::CompileShader(unsigned int shaderType, const std::string& sourceFilename) { std::string sourceCode; std::string line; std::ifstream shaderFile; shaderFile.open(sourceFilename); while (getline(shaderFile, line)) { sourceCode << line; } shaderFile.close(); std::cout << sourceCode; } And this is the error I get:
ShaderHandler.cpp:30:20: error: invalid operands to binary expression ('std::string' (aka 'basic_string<char, char_traits<char>, allocator<char> >') and 'std::string') sourceCode << line; ~~~~~~~~~~ ^ ~~~~ Instead of sourceCode << line, which is obviously wrong, what shall be used?
sourceCode += line;?