과제 중 none printable 한 것들을 입력 받는 경우에 대한 예외를 처리하려고 하는데 그것을 입력 받는 방법을 몰라서 테스트를 못하고 있다.
추가적으로 널을 입력 받는 방법도 궁금하다.
일단 내가 해결 한 방법은 ctrl +v 를 입력하면 신기하게도 22 이렇게 나오고 ctrl m을 하면 원하는 0 값이 나온다.
테스트 코드
#include <iostream>
int main()
{
std::string command;
while (true) {
std::string command;
getline(std::cin,command);
std::cout << (int)command[0] << std::endl;;
std::cout << command << std::endl;;
}
}
단축키도 매핑되어있고, 시그널도 있어서 모든 ctrl알파벳이 아스키 값을 가지는 것은 아닌 것 같지만 cin에 nonprintable한 값을 받는 건 성공했고, 아마 enter만 쳤을 때는 널이 들어가는 것 같긴 하다.
따라서 cin에 printable하지 않은 문자를 입력하는 방법은 ctrl하고 알파벳을 입력하면 들어갔다.
테스트 코드를 getline말고 cin을 사용해도 결과값을 다르지 않았다.
#include <iostream>
int main()
{
std::string command;
while (true) {
std::cin >> command;
// getline(std::cin,command);
std::cout << (int)command[0] << std::endl;;
std::cout << command << std::endl;;
}
}
Uploaded by N2T