2014-08-29 29 views
1

我想打开包含Blender球体的顶点和面的.obj文件。问题是我无法看到,对于我的生活,打开包含.obj数据的文件。我尝试使用普通的C++方式写入.txt文件,以检查应用程序创建它的位置,并尝试将.obj文件放入该文件夹中。我已经使用写入.txt文件的代码如下:从DirectX 11.2应用程序打开或创建文件

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"); 

我发布的代码不工作,文件犯规甚至可以创建。从哪里可以尝试加载.obj文件,为什么我甚至不能创建常规.txt文件以找出应用程序放置它们的位置。

我曾经尝试加载数据如下代码:

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"); 
     } 

任何帮助,将不胜感激。

+0

执行下列任一'DebugPrint'语句得到执行?你确定你正在寻找正确的地方吗?如果当前目录不是您所假设的,您可能需要使用绝对路径名。 – 2014-08-29 18:02:17

+0

是的,DebugPrint得到打印,从else子句中的一个说,该文件已加载。此外,我试图打印.is_open(),它总是输出false。不仅如此,但该文件甚至不会创建,我已经检查过。我不知道该怎么办? – miso 2014-08-30 11:24:30

回答

1

我发现在处理文件时我不能使用常规C++,因为DirectX在处理这些文件时有一些额外的限制。不过,幸运的是我发现的文件需要在以下文件夹:

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

我使用的代码是:

 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"); 
     } 
+0

我试图写入文件 - 但它不适用于我。 – pookie 2016-02-02 12:03:44

相关问题