2013-04-07 113 views
0

我编写了一个脚本语言,并且正在编写一个程序,它将1:请求您的路径以读取脚本,并且2:将代码编译为自定义的十六进制数,并由另一个程序读取为我做艰苦的工作。我的问题是我无法创建一个新文件并将自定义的十六进制代码写入该文件。创建和编写文件C++

这里是我的代码示例:我希望它做一个新.whatevertheheckyouwanttocallit文件,并写入到它的工作文件

#include <iostream> 
#include <string> 
#include <Windows.h> 
#include <wincon.h> 
#include <fstream>; 
using namespace std; 

int main(){ 
string path; 
string title; 
cout << "Enter your path to compile your *.egSCRIPT file: "; 
cin >> path; 
cout << "Enter the title for the new file"; 
cin >> title; 

ofstream myfile(path+"\\"+title+".myScriptLanguage"); 
myfile.open(path); 
myfile << "IT WORKS!!!"; 
myfile.close(); 
return 0; 
} 

!只是一个样本。我最终将写入一个自定义的十六进制代码系统,供我的解释器读取。提前致谢。

+0

你具体看到什么错误? – 2013-04-07 23:41:28

+0

我没有错误。只是为了测试,我会写出路径,并且'应该'创建一个.wav文件并写到它上面它工作!!!。 – 2013-04-07 23:43:06

+0

你的实际结果是?我不明白你的问题... – 2013-04-07 23:45:59

回答

1
ofstream myfile; 
myfile.open(path+"\\"+title+".myScriptLanguage"); 
myfile << "IT WORKS!!!"; 
myfile.close(); 

试试上述;

+0

我发现我的问题。这是路径本身。当我写道,我有一个空间,所以我实际上开始一个新的输入,并没有得到整个路径,因为它分为两部分。 – 2013-04-07 23:59:36

+0

很高兴知道你的工作。 – nommyravian 2013-04-08 00:01:50