Hi,
I was wondering if anybody knew how to get special characters such as ctrl-a from the command line in C++ as well as display them when the user presses the keys. Thanks
Amish
Hi,
I was wondering if anybody knew how to get special characters such as ctrl-a from the command line in C++ as well as display them when the user presses the keys. Thanks
Amish
Well, what are the conventions of the command line interpreter you're using to call your program in the first place.
You could start by telling us which OS you're on.
Sorry I misphrased my question. I should not have said command line. I am using windows primarily but the code will be ported to linux eventually. So my program prints out some questions and asks for answers and if the user inputs ctrl-a at any time, it should quit the program. So the user should see ctrl-a when he/she presses it, be able to delete it and if he presses enter, the program should recognise ctrl-a and exit. Thanks
Amish
Works for me on Linux
Code:#include <iostream> using namespace std; int main () { char buff[100]; while ( cin.getline(buff,sizeof buff) ) { if ( buff[0] == '\x01' ) { cout << "Bye now" << endl; break; } else { cout << "Normal process of line " << buff << endl; } } return 0; } $ g++ foo.cpp $ ./a.out hello world Normal process of line hello world next is ctrl-a Normal process of line next is ctrl-a ^A Bye now
Thanks for the answer.
Amish