摘要: 异常是程序运行时出现的不正常,比如内存耗尽或输入错误。异常机制提供程序中错误检测与错误处理部分的通信。包括:throw表达式:if(expression) throw runtime_error("error");do otherthingtry块try{program}catch(expression){handle-statements;}由标准库定义的一组异常类 阅读全文
posted @ 2011-06-29 20:47 hailong 阅读(314) 评论(0) 推荐(1) 编辑
摘要: 就是上一个题目的改写,灰常简单:#include <iostream>#include<string>using namespace std;int main(){ string cur,pre; bool flag = true; cout << "Please input string: " ; while (cin >> cur ) { if (cur == pre && cur[0] >= 'A' && cur[0] <= 'Z') { cou 阅读全文
posted @ 2011-06-29 20:34 hailong 阅读(296) 评论(0) 推荐(0) 编辑
摘要: 这次参考之前C++primer的习题答案,的确比较方便:问题是比较输入一系列string,如果发现连续相同的string则输入结束,否则循环进行:#include <iostream>#include<string>using namespace std;int main(){ string cur,pre; bool flag = true; cout << "Please input string: " ; while (cin >> cur ) { if (cur == pre) { if(!cur.empty()) c 阅读全文
posted @ 2011-06-29 20:12 hailong 阅读(288) 评论(0) 推荐(0) 编辑
摘要: 比较string大小,其实很简单,练手吧,快改找工作了,谁跟我提点建议啊?谢谢啦只看了C++,据说还要考察操作系统神马的:不说了,把代码贴上吧:#include <iostream>#include<string>using namespace std;int main(){ string s1,s2; bool flag = true; cout << "Please input two strings s1 and s2:" << endl; while (flag == true && cin>&g 阅读全文
posted @ 2011-06-29 19:48 hailong 阅读(327) 评论(0) 推荐(0) 编辑