string
입력을 두 개의 다른 int
으로 어떻게 분할합니까?두 개의 int 로의 C++ 분할 문자열 입력
나는 입력에 두 개의 서로 다른 분수를 (같은 2/3
) 프로그램을 쓰고 있어요 및 문자열로 2/3
에 읽고 싶은와 구분합니다 (/
)하여 분할하고있다.
예 :
Input: 2/3
Values:
int num = 2;
int denom = 3;
예 2 :
Input: 11/5
Values:
int num = 11;
int denom = 5;
감사합니다! "2/3"와 같은 매우 간단 뭔가를
잘 할 수 있습니다 : http://stackoverflow.com/questions/14265581/parse-split-a-string-in-c-using-string-delimiter-standard-c to 문자열을 분할하면 http://stackoverflow.com/questions/194465/how-to-parse-a-string-to-an-int-in-c 문자열을 int로 변환 할 수 있습니다. – Eddge
간단한 작업을 위해서'int a, b; char c; std :: cin >> a >> c >> b;' – Logman
''cin' 대신에'stringstream' 객체를 사용할 수 있다는 것을 잊어 버렸습니다. – Logman