【发布时间】:2015-11-20 14:31:36
【问题描述】:
大家好,所以我快速编写了一个测试程序来向您展示我遇到的问题。
我正在使用 fstream 将数据写入我的游戏的文件,以便他们可以加载和保存他们的变量。
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::ofstream outputFile;
outputFile.open("PlayerData"); // This creates the file
std::string Name;
int Age;
std::cout << "Your Name: ";
std::cin >> Name;
outputFile << Name << std::endl;
std::cout << "Your Age: ";
std::cin >> Age;
outputFile << Age << std::endl;
outputFile.close();
return 0;
}
当我运行程序时,它会在以下位置创建“PlayerData”文件:
Visual Studio 2013\Projects\TestFilePathing\TestFilePathing
一切正常,但我不想将 PlayerData 文件转储到 TestFilePathing 目录中,而是将其创建到子目录中以用于组织目的。
谢谢:D
【问题讨论】: