Opening or creating a file from a DirectX 11.2 app

2019-08-13 03:22发布

I am trying to open an .obj file which contains the vertices and faces of a sphere from Blender. The problem is i can't seem, for the life of me, open the file which contains the .obj data. I have tried using a normal C++ way to write to .txt file to check where would the appilcation create it, and maybe try to put the .obj file in that folder. The code i have used to write to the .txt file is as follows:

std::ofstream myfile("nestotamo.txt");
if (myfile.is_open())
{
    myfile << "This is a line.\n";
    myfile << "This is another line.\n";
    myfile.close();
}
else DebugPrint("Unable to open file");

The code i posted doesn't work, the file doesnt even get created. From where should i try to load the .obj file, and why can't i even create a regular .txt file to find out the location where the app places them.

The code i used to try to load the data is as follows:

   std::wifstream fileIn(path.c_str());

        if (fileIn)
        {
            while (fileIn)
            {
                wchar_t line[64];
                fileIn.getline(line, 64);
                DebugPrint(line);
            }
        }
        else {
            DebugPrint("\t The file wasnt loaded...\n");
        }

Any help would be much appreciated.

标签: c++ file
1条回答
戒情不戒烟
2楼-- · 2019-08-13 04:06

I have found out that i can't use regular c++ when working with files becuase DirectX has some additional constrictions on working with those. But, luckily i have found that the file needs to be in the following folder:

Solution_Name\x64\Debug(or Release)\Projekt_Name\AppX

The code i used is:

        std::wifstream fileIn(path.c_str());

        if (fileIn)
        {
            DebugPrint("The file loading begun: \n\n");

            while (fileIn)
            {
                wchar_t line[64];
                memset(line, '\0', 64);
                fileIn.getline(line, 64);

                DebugPrint(line);
                DebugPrint("\n");
            }
        }
        else {
            DebugPrint("\t The file wasnt loaded...\n");
        }
查看更多
登录 后发表回答