【发布时间】:2020-08-28 14:19:59
【问题描述】:
我正在编写一个需要读取文件并将其所有内容放入字符串变量的方法。
这是我尝试过的:
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;
}
这是我得到的错误:
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;
~~~~~~~~~~ ^ ~~~~
sourceCode << line,显然是错误的,应该用什么?
【问题讨论】:
-
sourceCode += line;?
标签: c++