That's what I tried, but it skips the input part.
This is what I have.
Sorry, the variables are in portuguese... But you're programmers, I think you'll get it
Code:
int Opcao;
do
{
cout<< "Pretende criar um ficheiro novo ou abrir um guardado? (1 - Criar Novo / 2 - Abrir Guardado): ";
cin>> Opcao;
}while(Opcao!=1 && Opcao!=2);
if(Opcao==1)
{
char Texto[2000]; //<------------ I wanted this to be an unlimited char array.... but this will do for now. I'll change it later.
cout<< "Escreva o texto: " <<endl;
cin>> Texto;
}else
{
string Caminho;
cout<< "Escreva o caminho para o ficheiro: ";
getline(cin, Caminho); //<------- It skips this part, so I dont even have a chance to input anything.
ifstream Ficheiro(Caminho.c_str());
if(!Ficheiro.fail())
{
cout<< "Falha ao abrir o ficheiro." <<endl;
cout<< "Verifique se escreveu correctamente o caminho." <<endl;
cout<< "Exemplo: C:\user\folder\texto.txt" <<endl;
}
else
{
while (!Ficheiro.eof())
{
cout<< "ahh!"; //(just for testing)
}
Ficheiro.close();
}
}
So the main problem seems to be on the getline, that just stops/skips... I'm working with VC++ 2008, btw.