私のプロジェクトでは、ファイル名を指定してテクスチャをロードするために使用します。ここで、 sconst char* app_dir(std::string fileToAppend);
を返し、アプリケーション名を。で変更するこの関数を作成しました。char *では文字列操作を簡単にすることができないので、を使用します。私のテクスチャローダーはファイル名にconstchar*を使用するため、c_str()に戻す必要があります。これで、ASCIIシンボル文字のシーケンスが生成されます(バグ)。のリターンタイプをに変更することで、すでに問題を修正しています。しかし、なぜそれが起こっているのですか?main
argv[0]
fileToAppend
std::string
app_dir()
std::string
編集
サンプルコード:
//in main I did this
extern std::string app_filepath;
int main(int argc, char** arv) {
app_filepath = argv[0];
//...
}
//on other file
std::string app_filepath;
void remove_exe_name() {
//process the app_filepath to remove the exe name
}
const char* app_dir(std::string fileToAppend) {
string str_app_fp = app_filepath;
return str_app_fp.append(fileToAppend).c_str();
//this is the function the generates the bug
}
前に述べたように、戻り型をstd :: stringに変更することで、すでに機能しているものがあります。