gpt4 book ai didi

c++ - 创建和写入文件 C++

转载 作者:行者123 更新时间:2023-11-28 07:40:54 26 4
gpt4 key购买 nike

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

这是我的代码示例:

#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;
}

我希望它创建一个新的 .whatevertheheckyouwanttocallit 文件并写入该文件 IT WORKS!!!就像一个样本。我最终会在上面写一个自定义的十六进制代码系统,以供我的解释器读取。提前致谢。

最佳答案

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

试试上面的;

关于c++ - 创建和写入文件 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15869163/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com