简体   繁体   中英

Creating and writing a file C++

I have made a scripting language and I was writing a program which would 1: Ask for your path to read the script and 2: Compile the code into a custom Hexadecimal which would be read by another program to do the hard work for me. My problem is I cannot create a new file and write the custom hexadecimal code onto that file.

Here is an example of my code:

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

I want it to make a new .whatevertheheckyouwanttocallit file and write onto the file IT WORKS!!! just as a sample. I will eventually write onto it a custom hexadecimal system of code to be read by my interpreter. Thanks in advance.

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

Try the above;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM