I have the code below. If I enter the file's name immediately, it finds the file without a problem, and I do not have do to anything. If I, however, types in a file it does not locate first, it will not find the file in the coming sequences, even if it exists. Does anybody understand what is wrong? The file is in the same folder.
string fileName;
cout << "Ingrese nombre archivo de carga: " << endl;
cin >> fileName;
if (fileName == "0")
return false;
ifstream infile(fileName); //here it should be filename
while (true) {
if (infile) {
cout << "Cargando directorio..." << endl;
break;
} else {
cout << "ERROR: No se pudo abrir el archivo." << endl;
}
cout << "Ingrese nombre archivo de carga: " << endl;
cin >> fileName;
if (fileName == "0")
return false;
ifstream infile(fileName);
}
Aucun commentaire:
Enregistrer un commentaire