Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/03/2014, 12:37
Urban94
 
Fecha de Ingreso: marzo-2014
Ubicación: Buenos Aires
Mensajes: 59
Antigüedad: 10 años, 6 meses
Puntos: 0
Problema al crear archivos de texto en c++

muchachos les dejo esto por aca..
Código C++:
Ver original
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. void print_menu(int &v1, string &p1,bool &opt1, bool &opt2, bool &opt3, bool &opt4, bool &opt5, bool &opt6);
  8. void salidaTam(string p1, int salida);
  9. void salidaPer(string p1);
  10. void salidaFor(string p1);
  11. void salidaVir(string p1);
  12. void salidaCol(string p1);
  13. void sub_menu(int &v1,bool &opt1, bool &opt2, bool &opt3, bool &opt4, bool &opt5, bool &opt6);
  14.  
  15. int main()
  16. {
  17.     struct regtxt{
  18.         string tamanio;
  19.         string perforaciones;
  20.         string forma;
  21.         string virola;
  22.         string color;
  23.     };
  24.    
  25.     string subopc;
  26.     int resp;
  27.     int resp2;
  28.     int resp3;
  29.     bool opc1,opc2,opc3,opc4,opc5,opc6;
  30.     opc1=opc2=opc3=opc4=opc5=opc6=true;
  31.     regtxt registro;
  32.  
  33.     print_menu(resp,subopc,opc1,opc2,opc3,opc4,opc5,opc6);
  34.     while(resp != 6){
  35.         print_menu(resp,subopc,opc1,opc2,opc3,opc4,opc5,opc6);
  36.     }
  37.     return 0;
  38. }
  39.  
  40.  
  41. void salidaTam(string p1, int salida){
  42.     string linea;
  43.     ifstream fentrada("Botones.txt");
  44.     ofstream fsalida1("Salida1.txt");
  45.     while(!fentrada.eof()){
  46.         getline(fentrada,linea);
  47.             if (p1=="a"){
  48.                 if (linea.substr(0,1)=="c"){
  49.                     fsalida1<<linea<<endl;
  50.                 }
  51.             }
  52.             if (p1=="b"){
  53.                 if (linea.substr(0,1)=="m"){
  54.                     fsalida1<<linea<<endl;
  55.                 }
  56.             }
  57.             if (p1=="c"){
  58.                 if (linea.substr(0,1)=="g"){
  59.                     fsalida1<<linea<<endl;
  60.                 }
  61.             }
  62.     }
  63. }
  64.  
  65. void salidaPer(string p1){
  66.     string linea;
  67.     ifstream fentrada("Botones.txt");
  68.     ofstream fsalida1("Salida1.txt");
  69.     while(!fentrada.eof()){
  70.         getline(fentrada,linea);
  71.             if (p1=="a"){
  72.                 if (linea.substr(2,1)=="1"){
  73.                     fsalida1<<linea<<endl;
  74.                 }
  75.             }
  76.             if (p1=="b"){
  77.                 if (linea.substr(2,1)=="2"){
  78.                     fsalida1<<linea<<endl;
  79.                 }
  80.             }
  81.             if (p1=="c"){
  82.                 if (linea.substr(2,1)=="4"){
  83.                     fsalida1<<linea<<endl;
  84.                 }
  85.             }
  86.     }
  87. }
  88.  
  89. void salidaFor(string p1){
  90.     string linea;
  91.     ifstream fentrada("Botones.txt");
  92.     ofstream fsalida1("Salida1.txt");
  93.     while(!fentrada.eof()){
  94.         getline(fentrada,linea);
  95.             if (p1=="a"){
  96.                 if (linea.substr(4,4)=="Redo"){
  97.                     fsalida1<<linea<<endl;
  98.                 }
  99.             }
  100.             if (p1=="b"){
  101.                 if (linea.substr(4,4)=="Cuad"){
  102.                     fsalida1<<linea<<endl;
  103.                 }
  104.             }
  105.             if (p1=="c"){
  106.                 if (linea.substr(4,4)=="Tria"){
  107.                     fsalida1<<linea<<endl;
  108.                 }
  109.             }
  110.     }
  111. }
  112.  
  113. void salidaVir(string p1){
  114.     string linea;
  115.     ifstream fentrada("Botones.txt");
  116.     ofstream fsalida1("Salida1.txt");
  117.     while(!fentrada.eof()){
  118.         getline(fentrada,linea);
  119.             if (p1=="a"){
  120.                 if (linea.substr(9,3)=="Con"){
  121.                     fsalida1<<linea<<endl;
  122.                 }
  123.             }
  124.             if (p1=="b"){
  125.                 if (linea.substr(9,3)=="Sin"){
  126.                     fsalida1<<linea<<endl;
  127.                 }
  128.             }
  129.     }
  130. }
  131.  
  132. void salidaCol(string p1){
  133.     string linea;
  134.     ifstream fentrada("Botones.txt");
  135.     ofstream fsalida1("Salida1.txt");
  136.     while(!fentrada.eof()){
  137.         getline(fentrada,linea);
  138.             if (p1=="a"){
  139.                 if (linea.substr(13,5)=="Blanc"){
  140.                     fsalida1<<linea<<endl;
  141.                 }
  142.             }
  143.             if (p1=="b"){
  144.                 if (linea.substr(13,5)=="Negro"){
  145.                     fsalida1<<linea<<endl;
  146.                 }
  147.             }
  148.             if (p1=="c"){
  149.                 if (linea.substr(13,5)=="Rojo "){
  150.                     fsalida1<<linea<<endl;
  151.                 }
  152.             }
  153.             if (p1=="d"){
  154.                 if (linea.substr(13,5)=="Amari"){
  155.                     fsalida1<<linea<<endl;
  156.                 }
  157.             }
  158.     }
  159. }
  160.  
  161. void sub_menu(int &v1,bool &opt1, bool &opt2, bool &opt3, bool &opt4, bool &opt5, bool &opt6, int &salida){
  162.  
  163.     int v2;
  164.     do{
  165.         cout << "Elija como quiere seguir: " <<endl;
  166.         cout << "1. Seguir aplicando filtros a la caja actual" <<endl;
  167.         cout << "2. Crear otra caja" <<endl;
  168.         cout << "3. Salir del programa" <<endl;
  169.         cin>>v2;
  170.     }while(v2 <= 0 || v2 >3);
  171.  
  172.     if(v2==1){
  173.         return;
  174.     }
  175.     if(v2==2){
  176.         opt1=opt2=opt3=opt4=opt5=opt6=true;
  177.         salida++;
  178.     }
  179.     if(v2==3){
  180.         v1 = 6;
  181.     }
  182. }
  183.  
  184.  
  185. void print_menu(int &v1, string &p1,bool &opt1, bool &opt2, bool &opt3, bool &opt4, bool &opt5, bool &opt6){
  186.  
  187.     int resp=0,cond1=0,cond2=0,cond3=0,cond4=0,cond5=0;
  188.     int salida=1; //variable que define el nombre de salida (todavia no se como aplicarla)
  189.     string subopc;
  190.     do{
  191.         cout << "Elija como quiere filtrar los botones: " <<endl;
  192.         if (opt1){
  193.             cout << "1. Tamanio" <<endl;
  194.         }
  195.         if (opt2){
  196.             cout << "2. Perforaciones" <<endl;
  197.         }
  198.         if (opt3){
  199.             cout << "3. Forma" <<endl;
  200.         }
  201.         if (opt4){
  202.             cout << "4. Virola" <<endl;
  203.         }
  204.         if (opt5){
  205.             cout << "5. Color" <<endl;
  206.         }
  207.         if (opt6){
  208.             cout << "6. Salir del programa" <<endl;
  209.         }
  210.  
  211.         cin>> v1;
  212.  
  213.         if(v1 == 1 && opt1 != false){
  214.             opt1 = false;
  215.             do{
  216.                 cout << "Eliga la subopcion" <<endl;
  217.                 cout << "a. Chico" << endl;
  218.                 cout << "b. Mediano" << endl;
  219.                 cout << "c. Grande" << endl;
  220.                 cin >> p1;
  221.             }while (p1 < "a" || p1 > "c");
  222.             salidaTam(p1,salida);
  223.         }
  224.         if (v1 == 2 && opt2 != false){
  225.             opt2 = false;
  226.             do{
  227.                 cout << "Eliga la subopcion" <<endl;
  228.                 cout << "a. 1 Perforacion" << endl;
  229.                 cout << "b. 2 Perforaciones" << endl;
  230.                 cout << "c. 4 Perforaciones" << endl;
  231.                 cin >> p1;
  232.             }while (p1 < "a" || p1 > "c");
  233.             salidaPer(p1);
  234.         }
  235.         if (v1 == 3 && opt3 != false){
  236.             opt3 = false;
  237.             do{
  238.                 cout << "Eliga la subopcion" <<endl;
  239.                 cout << "a. Redondo" << endl;
  240.                 cout << "b. Cuadrado" << endl;
  241.                 cout << "c. Triangulo" << endl;
  242.                 cin >> p1;
  243.             }while (p1 < "a" || p1 > "c");
  244.             salidaFor(p1);
  245.         }
  246.         if(v1 == 4 && opt4 != false){
  247.             opt4 = false;
  248.             do{
  249.                 cout << "Eliga la subopcion" <<endl;
  250.                 cout << "a. Con virola" << endl;
  251.                 cout << "b. Sin virola" << endl;
  252.                 cin >> p1;
  253.             }while (p1 < "a" || p1 > "b");
  254.             salidaVir(p1);
  255.         }
  256.         if(v1 == 5 && opt5 != false){
  257.             opt5 = false;
  258.             do{
  259.                 cout << "Eliga la subopcion" <<endl;
  260.                 cout << "a. Blanco" << endl;
  261.                 cout << "b. Negro" << endl;
  262.                 cout << "c. Rojo" << endl;
  263.                 cout << "d. Amarillo" << endl;
  264.                 cin >> p1;
  265.             }while (p1 < "a" || p1 > "d");
  266.             salidaCol(p1);
  267.         }
  268.         sub_menu(v1,opt1,opt2,opt3,opt4,opt5,opt6,salida);
  269.     }while(v1 <= 0 || v1 >6);
  270.  
  271. }


Código C++:
Ver original
  1. void salidaTam(string p1, int salida){
  2.     string linea;
  3.     ifstream fentrada("Botones.txt");
  4.     ofstream fsalida1("Salida1.txt");
  5.     while(!fentrada.eof()){
  6.         getline(fentrada,linea);
  7.             if (p1=="a"){
  8.                 if (linea.substr(0,1)=="c"){
  9.                     fsalida1<<linea<<endl;
  10.                 }
  11.             }
  12.             if (p1=="b"){
  13.                 if (linea.substr(0,1)=="m"){
  14.                     fsalida1<<linea<<endl;
  15.                 }
  16.             }
  17.             if (p1=="c"){
  18.                 if (linea.substr(0,1)=="g"){
  19.                     fsalida1<<linea<<endl;
  20.                 }
  21.             }
  22.     }
  23. }


Lo que yo quiero hacer es que cuando se decida crear otra caja en mi programa principal, que se cree un nuevo archivo con distinto nombre pero no se como hacer
les deje el codigo completo por las dudas pero no tengo idea, probe muchas cosas ya :/