-
C++연습_문자열 비교하기(string.compare)코딩Coding/C++_연습 2020. 9. 18. 08:38728x90
#include <iostream> #include <string> using std::cin; using std::cout; using std::endl; using std::getline; using std::string; int main() { string temp1, temp2; cout << "Enter first word : "; getline(cin, temp1); cout << "Enter second word : "; getline(cin, temp2); cout << "First word: " << temp1 << endl << "Second word: " << temp2 << endl; if (temp1 == temp2) { cout << "Same word" << endl; } if (temp1.compare(temp2) < 0) { cout << "The two words are different." << endl; } return 0; }
결과
stackoverflow.com/questions/24957965/comparing-strings-c/24958019
Comparing strings, c++
I have a question: Let's say there are two std::strings and I want to compare them, there is the option of using the compare() function of the string class but I also noticed that it is possible u...
stackoverflow.com
반응형'코딩Coding > C++_연습' 카테고리의 다른 글
C++연습_반복되는 문자 숫자 세기_입력하는거로 수정해야함 (0) 2020.11.28 C++연습_문자열 연결 (0) 2020.11.26 C++연습_Hello, World 출력하기 (0) 2020.10.17 C++연습_프로그램 실행 폴더 알아내기 (0) 2020.09.22 C++연습_전역변수(Global variable) (0) 2020.09.20 C++연습_날짜와 시간을 문자열로 변환하기(localtime) (0) 2020.09.18 C++연습_난수 생성하기(Random number) (0) 2020.09.17 C++연습_Hello World출력 (0) 2020.09.02