I'm trying to do an exercise where I've to open a txt file, but I don't know why it doesn't open, and the program stops doing nothing during its execution
My bet is that your if (!Puntos_Muestra) is executing too quick for you to see that it is failing out. In this case your file is not open and your else codition is never met. Try piping the failure code to an ifstream object if it fails.
I don't understand you at all... If my file isn't open, de if condition shows me that and If the name is correct, the program stops... :S I don't understand...
I'm not trying to insult anyone my spanish is truley this horrific but I'm making an honest effort to learn and bring my little one up bi-lingual. If you include programming this makes four languages for me so it's pretty difficult.
Tu archievo es no abierto, tu programa es no ver el archievo. Es 'a.txt' en mismo carpeta? The file is not open, the program is not seeing the file. Is 'a.txt' in the same folder?
Yes, it's in the same folder... Anyway, my code must open a file in any folder, given its path... But I'm trying it with the file in the same folder to make it easier...
I don't understand why if i give a wrong path, or a wrong file name, the if condition executes correctly saying that the file was not found... and why if I give the correct file name, the else condition stops...
I found an error. The file is open correctly, the problem is that numbers aren't read..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
ifstream Puntos_Muestra (route.c_str());
if (Puntos_Muestra.is_open())
{
cout << "Hello" << endl;
float x;
Puntos_Muestra >> x;
cout << x;
}
// Se comprueba que el fichero se ha abierto correctamente
//if (!Puntos_Muestra)
else
{
cout << endl << endl;
cout << "No se pudo abrir el fichero. No existe o la ruta no es valida.";
cout << endl << endl;
exit(1);
}