Programing/C and CPlusPlus
-
[C] Key PressPrograming/C and CPlusPlus 2019. 3. 4. 14:45
void set_mode(int want_key) { static struct termios old, newk; if (!want_key) { tcsetattr(STDIN_FILENO, TCSANOW, &old); return; } tcgetattr(STDIN_FILENO, &old); newk = old; newk.c_lflag &= ~(ICANON | ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &newk); } int get_key() { int c = 0; struct timeval tv; fd_set fs; tv.tv_usec = tv.tv_sec = 0; FD_ZERO(&fs); FD_SET(STDIN_FILENO, &fs); select(STDIN_FILENO + ..
-
[C++] Exception overloadingPrograming/C and CPlusPlus 2019. 2. 25. 16:34
#include #include #include #include using namespace std; /* Define the exception here */ class BadLengthException : public exception { public: BadLengthException(int n) { stringstream ss; ss > T; while(T--) { string username; cin >> username; try { bool isValid = checkUsername(username); if(isValid) { cout
-
C++ 복사생성자/대입연산자Programing/C and CPlusPlus 2012. 7. 4. 16:06
□ 복사생성자 (copy constructor) 객체와 객체가 복사될때 호출되는 생성자 함수 □ 복사생성자 호출시점 1. 객체생성시 객체에 인수로 전달 2. 함수호출시 객체를 인수로 전달 3. 함수에서 객체를 리턴할때 ###cpp #include #include #include #include #include using namespace std; class Star { private: char *name; int age; public: Star(); Star(char *, int); ~Star(); Star::Star (Star &_s); Star& operator=(Star &); void Disp() const; } ; Star::Star():age(0) { name = new char [strlen..