I made this program in Java but I am fairly new in C++ and using strings has been imposible. I was wondering if anyone could point me in a direction for me to "translate" this program to C++. Just how to use strings and maybe something you see in my code that is worth mentioning. Note: I am not asking for any of you for a direct translation, just info for me to do it, the code is reference.
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.Scanner;
public class DragonCurve{
public static void main(String[] args){
try{
Scanner sc = new Scanner(System.in);
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
int n;
while((n = Integer.parseInt(sc.nextLine()))!=-1){
log.write(dragon(n)+"\n");
}
log.flush();
}catch(Exception e){
e.printStackTrace();
}
}
public static String dragon(int n){
if(n>2){
String aux = dragon(n-1);
return aux+"L"+reverse(aux);
}else if(n==2)
return "LLR";
else if(n==1)
return "L";
else if(n==0)
return "";
return "";
}
public static String reverse(String aux){
String ans = "";
for(int i = aux.length();i>0;i--){
if(aux.charAt(i-1)=='L')
ans+='R';
else
ans+='L';
}
return ans;
}
}