所以给出这个背景 我正在制作一个脚本,为我正在运行的某些游戏生成配置文件。 我此时只是试图让脚本生成文件并将其放在所述游戏的目录中。 (这仍在进行中。我没有办法获得用户输入。但首先我需要它将它放在正确的目录中。) 在这个例子中它是我的世界。
但是我无法在任何论坛上找到任何帖子,或者在stackoverflow上找到任何有效的帖子。 可能是因为我错过了其余的代码,因为大多数人只提供3行代码。
重点是我没有经历过c ++,因为我从未使用过它。 所以我希望有人可以帮我修复它。
是的,我添加了我到目前为止所获得的完整代码,因为它可能已经填满了#34; shit"和一个比它需要的更长的战利品所以任何帮助都会很好。
最后的注意事项* 我正在使用MS visual studio express 2013
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
// comment
/*
multi
line
comment
*/
//locked
// server ip : string
string ip = "127.0.0.1";
//server port : integer 1-65534
string port = "25565";
//world name : string
string world = "world";
//amount of allowed players : integer 0-2147483647
string mxpla = "20";
//view distance : integer 3-15
string viedis = "10";
//trexture pack :string
string texpack = "";
//user defined
// world gen setting : string (only used whit CUSTOMIZED leveltype)
string genset = "";
// allow flight : boolean true or false
string alfly = "true";
// level type : string DEFAULT, FLAT, LARGEBIOMES, AMPLIFIED, CUSTOMIZED --> same as DEFAULT unless generator settings is filled out
string levtype = "DEFAULT";
// level seed : string
string levseed = "";
// max build hight : integrer 0-256
string mxbh = "256";
//spawn npc : boolean true or false
string snpc = "true";
// whitelist : boolean true or false
string wlist = "false";
//spawn animals : boolean true or false
string sanimal = "true";
// hardcore mode : boolean true or false
string hc = "false";
//online mode : boolean true or false
string onmo = "true";
// pvp mode : boolean true or false
string pvp = "false";
//server difficulity : integer 0-3 0 peaceful - 3 hard
string diff = "1";
// game mode : integer 0-3 0 survival, 1 creative, 2 adventure and 3 spectator (dont use 3 on the server side)
string gamemo = "0";
// spawn mobs : boolean true or false
string smob = "true";
//generate structures : boolean ture or false
string genstru = "true";
// mesage of the day : string
string motd = "test";
int main() {
ofstream outFile;
// output file
outFile.open("test.properties");
// file generator
outFile << "generator-settings=" << genset << endl
<< "level-name=" << world << endl
<< "allow-flight=" << alfly << endl
<< "server-port=" << port << endl
<< "level-type=" << levtype << endl
<< "level-seed=" << levseed << endl
<< "server-ip=" << ip << endl
<< "max-build-height=" << mxbh << endl
<< "spawn-npcs=" << snpc << endl
<< "white-list=" << wlist << endl
<< "spawn-animals=" << sanimal << endl
<< "hardcore=" << hc << endl
<< "texture-pack=" << texpack << endl
<< "online-mode=" << onmo << endl
<< "pvp=" << pvp << endl
<< "difficulty=" << diff << endl
<< "gamemode=" << gamemo << endl
<< "max-players=" << mxpla << endl
<< "spawn-monsters=" << smob << endl
<< "generate-structures=" << genstru << endl
<< "view-distance=" << viedis << endl
<< "motd=" << motd << endl;
outFile.close();
return 0;
}
答案 0 :(得分:0)
如果要在VS以外的任何文件夹中创建输出文件,则应更改工作目录。进入Solution properties
- &gt; Configuration properties
- &gt; Debugging
- &gt; Working directory
并将值更改为首选路径。例如,写一下C:\Games\minecraft
答案 1 :(得分:0)
ofstream
的{{1}}方法采用完整路径,因此您可以这样指定:
open()