[英]Export From C++ Into Eclipse As Java Program
So I have a program that I wrote in C++ (it's a generator) and when you type in some options, it generates a java code in the console, but it can't be copy/pasted and is hard to read (that's just the way windows console is). 因此,我有一个用C ++编写的程序(它是一个生成器),当您键入一些选项时,它会在控制台中生成一个Java代码,但是它不能被复制/粘贴并且很难阅读(这只是Windows控制台的方式)。 Is there a way to make that generated java code export into eclipse so that the person can edit it? 有没有一种方法可以将生成的Java代码导出到eclipse中,以便该人可以对其进行编辑? Even better, could that code be exported to a .jar file? 更好的是,该代码可以导出到.jar文件吗?
You could always redirect the console output to a text file using > pipe: 您始终可以使用>管道将控制台输出重定向到文本文件:
C:\> myapp.exe > output.java
Alternatively, here is a tutorial on how to write to file in C++ http://www.cplusplus.com/doc/tutorial/files/ 另外,这是有关如何使用C ++写入文件的教程http://www.cplusplus.com/doc/tutorial/files/
Update: A short example on how to output the .java file. 更新:有关如何输出.java文件的简短示例。
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("Hello.java");
myfile
<< "public class Hello {" << endl
<< " public static void main(String[] args) {" << endl
<< " System.out.println(\"Hello World\");" << endl
<< " }" << endl
<< "}";
myfile.close();
return 0;
}
How about saving the generated code into a *.java file instead of printing it to the cosnole??? 如何将生成的代码保存到* .java文件中,而不是将其打印到cosnole? to generate a jar file you can either do it on the console using the command "jar" or use eclipse or something to generate the jar 要生成一个jar文件,您可以在控制台上使用命令“ jar”或使用eclipse或其他方式来生成jar
You have to read a bit about c++. 您必须阅读一些有关c ++的知识。 Here's how to handle file io http://www.functionx.com/cpp/articles/filestreaming.htm 这是处理文件io的方法http://www.functionx.com/cpp/articles/filestreaming.htm
cheers 干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.