Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: mrvaledon en 12 Mayo 2015, 03:27 am



Título: Porque No Me Deja Crear El File(OPCION 3) AYUDA!!!
Publicado por: mrvaledon en 12 Mayo 2015, 03:27 am
EN LA OPCION 3 NO ME DEJA CREAR EL FILE! SIN EMBARGO CUANDO HAGO ESO MISMO EN UN MAIN SOLO SI ME DEJA!

Código:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;

struct costumerInfo
{
string name;
string addr;
string city;
string state;
string zip;
string phoNum;
};

int main()
{
int menupri = 0; //contador del do while(menupri)
int choicemp; //variable que elige la opcion en el menu principal
string filenamemov = "dataMovies.dat";
string line;

do //menu principal
{
cout << "------ MOVIE DATABASE SYSTEM -------" << endl;
cout << "------------------------------------" << endl;//menu header

cout << "Select Your Choice:                 " << endl;
cout << "1. Edit Costumer Info               " << endl;
cout << "2. Add Movie Record To A Costumer   " << endl;
cout << "3. Create New Costumer              " << endl;
cout << "4. Search Costumer Record           " << endl;
cout << "5. Delete Costumer Record                             " << endl;
cout << "------------------------------------" << endl;
cout << "Please Enter Your Choice: ";
cin >> choicemp;

system("cls");

switch (choicemp)//opciones del menu principal
{
case 1://presenta la opcion 1
{
//EDIT COSTUMER INFO

system("pause");
system("cls");
break;
}

case 2://presenta la opcion 2
{
//ADD MOVIE RECORD TO A COSTUMER

system("pause");
system("cls");
break;
}

case 3://presenta la opcion 3 *FILE NO SE CREA VERIFICAR!!!
{
//cout << "--- CREATE NEW COSTUMER RECORD ---" << endl;
//cout << "----------------------------------" << endl;

ofstream newcostFile, movFile;
costumerInfo infoCost;

cout << "\nEnter New Costumer Name: ";
getline(cin, infoCost.name);

newcostFile.open(infoCost.name);

if (newcostFile.fail())
{
cout << "\nThe File Cannot Be Created Correctly." << endl;
system("pause");
exit(1);
}

cout << "\nAddress: ";
getline(cin, infoCost.addr);

cout << "\nCity: ";
getline(cin, infoCost.city);

cout << "\nState: ";
getline(cin, infoCost.state);

cout << "\nZIP Code: ";
cin >> infoCost.zip;

cout << "\nPhone Number: ";
getline(cin, infoCost.phoNum);

newcostFile << "Name\t" << infoCost.name << endl
<< "Address \t" << infoCost.addr << endl
<< "City \t" << infoCost.city << endl
<< "State \t" << infoCost.state << endl
<< "ZIP Code \t" << infoCost.zip << endl
<< "Phone Number \t" << infoCost.phoNum << endl;

movFile.open(infoCost.name + "Movies");

if (movFile.fail())
{
cout << "\nThe File Cannot Be Create Correctly.";

system("pause");
exit(1);
}

newcostFile.close();
movFile.close();

system("pause");
system("cls");
break;
}

case 4:
{
//SEARCH COSTUMER RECORD

system("pause");
system("cls");
break;
}

case 5:
{
//DELETE COSTUMER RECORD

system("pause");
system("cls");
break;
}

default://cierra el programa
{
return 0;
break;
}
}

} while (menupri != 6);

system("pause");
return 0;
}


Título: Re: Porque No Me Deja Crear El File(OPCION 3) AYUDA!!!
Publicado por: Seyro97 en 18 Mayo 2015, 02:26 am
Yo he probado con este código, y funciona:

Código
  1. cout << "\nEnter New Costumer Name: ";
  2. cin.ignore(); // Esto es lo que añadí
  3. getline(cin, infoCost.name);
  4.  

Espero que te sirva :P


Título: Re: Porque No Me Deja Crear El File(OPCION 3) AYUDA!!!
Publicado por: Seyro97 en 18 Mayo 2015, 03:18 am
Si tienes más dudas, no dudes (XD) en preguntar!


Título: Re: Porque No Me Deja Crear El File(OPCION 3) AYUDA!!!
Publicado por: mrvaledon en 18 Mayo 2015, 05:16 am
Gracias!!!