0

trying to ifstream from a cin...

if (schc == "cal"){ system("cls"); string calus, calpa, calfi, calline; cout << "\t Type the DomainID.datc(ex: Youtube.datc) to get its credentials: \n"; cin >> calfi; ifstream calfic( calfi ); // problem is here ^^^^ if (!calfic){ cout << calfi << ' ' << "doesn't exist. \n"; refuse(); returntohome(); } for (int y = 0; getline(calfic, calline) && y < 2; y++){ switch(y){ case 1: cout << "Your username for " << calfi << " is : " << calline; break; case 2: cout << "Your password for " << calfi << " is : " << calline; break; cin.get(); returntohome(); } } i can't manage to read data using ifstream from a user-specified file with cin >>; Any suggestions? I'm kind of a newbie

24th Sep 2017, 4:43 PM
Iulian Andrei
Iulian Andrei - avatar
3 Answers
+ 1
if (schc == "cal"){ system("cls"); string fnm, lime; cin >> fnm; ifstream fin(fnm.c_str()); if (!fin){ cout << fnm << ' ' << "doesn't exist. \n"; refuse(); returntohome(); } for (int y = 1; getline(fin, lime) && y <= 2; y++){ switch(y){ case 1: cout << "Your username is: " << lime << endl; break; case 2: cout << "Your password is: " << lime << endl; break; } }
24th Sep 2017, 5:11 PM
Iulian Andrei
Iulian Andrei - avatar
0
Found this to be working in my case. No more need for help c: ystem("cls"); string fnm, lime; cin >> fnm; ifstream fin(fnm.c_str()); if (!fin){ cout << fnm << ' ' << "doesn't exist. \n"; refuse(); returntohome(); }
24th Sep 2017, 5:08 PM
Iulian Andrei
Iulian Andrei - avatar