扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
本示例中的 main() 创建不同的 Pair 并将它们进行比较:
int main(int argc, char* argv[]) { Pair<double,int> first(2.2,3); first.display(); Pair<double,int> second(2.1,4); second.display(); if (first > second) cout << "first is greater" << endl; else cout << "first is not greater" << endl; Pair<char*,int> third("Hello",4); third.display(); Pair<char*,int> fourth("World",5); fourth.display(); if (third > fourth) cout << "third is greater" << endl; else cout << "third is not greater" << endl; return 0; }
要编译该示例,请使用以下命令行:
cl /EHsc conformance.cpp
要运行:
conformance
您可以看到以下输出:
2.2 3 2.1 4 first is greater Hello 4 World 5 third is not greater
Pair 显示第一个更大,因为 2.2 大于 3。Pair 显示小于等于,因为“Hello”不大于“World”。
查看本文来源濡傛灉鎮ㄩ潪甯歌揩鍒囩殑鎯充簡瑙T棰嗗煙鏈€鏂颁骇鍝佷笌鎶€鏈俊鎭紝閭d箞璁㈤槄鑷抽《缃戞妧鏈偖浠跺皢鏄偍鐨勬渶浣抽€斿緞涔嬩竴銆�