Рассматривая следующий код (он использует OpenGL, но это не то, о чем мой вопрос): < /p>
#include
#include
#include
#include
using std::string;
...
//Example func for loading content of external file
string load(string src) {
std::ifstream file(src);
if (file.fail()) {
output("FILE", "Failed to access content of file at location " + string(src), 1);
}
string content;
while (!file.eof()) {
char character;
file.get(character);
content.push_back(character);
}
content.pop_back();
return content;
};
unsigned int compileShader() {
// Create shader
unsigned int shader;
shader = glCreateShader(type);
string codeString = load(src); // Load shader from file here
const char* code = codeString.c_str(); // Convert to C string (needed in further computations)
// What does the code look like?
std::cout
Функция compileshader (), таким образом, загружает содержимое внешнего файла, записанного в GLS Аргумент в отношении функции GL Glshadersource (). И это работает просто отлично. < /P>
фокусируется только на этом фрагменте, однако: < /p>
string codeString = load(src); // Load shader from file here
const char* code = codeString.c_str(); // Convert to C string
// What does the code look like?
std::cout
const char* code = load(src).c_str(); // Load shader from file and convert to C string
// What does the code look like?
std::cout
Что предотвращает его работать? Какова основная механика за этим? Спасибо за ответы. Я относительно новичок в C ++, так что это может быть действительно просто, только я не знаю, где еще именно для поиска ответа.
Подробнее здесь: https://stackoverflow.com/questions/615 ... y-a-method