I can easily redirect the standard output to the terminal but getting the standard input to redirect to the terminal isn't working. I'm stumped.
Easy newbie mistake?Code:#include <iostream> #include <fstream> #include <string> using namespace std; int main(int argc, char* argv[]){ string username; char c; ifstream termin("/dev/tty"); ofstream termout("/dev/tty"); termout << "Enter SQL user name: "; termout.flush(); // termin.getline(username, 16); //didn't work // termin >> username; //Me neither // while ((c = termin.get()) > ' ');//Nope cout << username << endl; }
[edit]
does work but, of course, that won't handle redirected input.Code:while (isgraph(c = cin.get())) username += c;
[/edit]



LinkBack URL
About LinkBacks


