En el siguiente programa, el getline hace como si no existiera.Directamente no hace nada. Lo he probado en otro mini-programa y funciona perfectamente, pero en éste no.¿Sabéis qué sucede?
Código:
#include <iostream>
#include <fstream>
using namespace std;
void EscribirEnFichero();
void LeerEnFichero();
int main(){
string PreguntaLeerOEscribir;
Vuelta1:
cout<<"Desea (E)scribir o (L)eer un archivo"<<endl;
cin>> PreguntaLeerOEscribir;
if ((PreguntaLeerOEscribir=="E") || (PreguntaLeerOEscribir=="e")){
EscribirEnFichero();
}
else if ((PreguntaLeerOEscribir=="L") || (PreguntaLeerOEscribir=="l")){
LeerEnFichero();
}
else {
cout<<"No ha escrito una opcion valida.Intentelo otra vez"<<endl;
goto Vuelta1;
}
return 0;
}
void EscribirEnFichero(){
char NombreArchivo[128];
string Texto;
cout<<"Que nombre desea que tenga el archivo"<<endl;
cin>>NombreArchivo;
cout<<"Que desea escribir en el archivo"<<endl;
getline(cin,Texto); //Este es el getline que no funciona
ofstream fichero (NombreArchivo);
fichero<<Texto<<endl;
fichero.close();
system("pause()");
}
void LeerEnFichero(){
}