2016-11-26 16 views
0

をデバッグするときに私の問題がC++ファイルが見つからないのVisual Studioから2015

Shader* s = new Shader("Shaders\\test.vert", "Shaders\\test.frag"); 

または

Texture texture("test.png"); 

をやったときにVisual Studioがそれらを見つけることを拒否し、まだ.exeファイルのすべてを開くときにはあるということです適切に動作します。 Doing

Shader* s = new Shader("C:\\Users\\Public\\Google Drive\\vs projects\\Engine\\Debug\\Shaders\\test.vert", "C:\\Users\\Public\\Google Drive\\vs projects\\Engine\\Debug\\Shaders\\test.frag"); 

Visual Studioの問題を解決しますが、実際には私が探しているものではありません。

私はファイルを読んでいる道:私はデバッグ(x86の)モードでプロジェクトを実行していることを確認作った

static std::string read_file(const char* path) 
    { 
     FILE* file = fopen(path, "rt"); 
     fseek(file, 0, SEEK_END); 
     unsigned long length = ftell(file); 
     char* data = new char[length + 1]; 
     memset(data, 0, length + 1); 
     fseek(file, 0, SEEK_SET); 
     fread(data, 1, length, file); 
     fclose(file); 

     std::string result(data); 
     delete[] data; 

     return result; 
    } 

。どんな解決策ですか?

+0

シェイダーとは何ですか? – Danh

+0

@ダンあなたはシェイダーの内容を意味しますか? –

答えて

1

Visual StudioのC++プロジェクトの作業ディレクトリは、実行可能ファイルを含むディレクトリではなく、Visual Studioから実行するとプロジェクトディレクトリに設定されるためです。出典:Project Settings for a C++ Debug Configuration

作業ディレクトリ

  • は、あなたのEXEが置かれているプロジェクトディレクトリからの相対デバッグ中のプログラムの作業ディレクトリを指定します。 このフィールドを空白のままにすると、作業ディレクトリはプロジェクトディレクトリになります。リモートデバッグのために、プロジェクトディレクトリが

したがって、リモートサーバー上になり、Shaders\test.vertの絶対パスは、あなたのケースで

${path_to_your_project}\Shaders\test.vert 

があり、それはだ

C:\Users\Public\Google Drive\vs projects\Engine\Shaders\test.vert 

C:\Users\Public\Google Drive\vs projects\Engine\{project_name}\Shaders\test.vert 

エンジンがソリューションフォルダの場合

ファイルを正しいディレクトリ(プロジェクトディレクトリ)に移動するだけで、コードが機能します。

+0

私はそれがVisual Studio上のC#のようなものであると仮定しました。ここでは、デバッグ/リリースフォルダに.vhost.exeファイルが含まれています。ありがとう、完璧に働いた! :) –

関連する問題