fig10.01.cpp
来源:互联网 发布:女生脱毛知乎 编辑:程序博客网 时间:2024/06/05 06:21
#include<iostream>#include<string>using namespace std;int main(){string s1("happy");string s2("birthday");string s3;cout << "s1 is \"" << s1 << "\"; s2 is \"" << s2<< "\"; s3 is \""<< s3 <<'\"'<< "\n\nThe results of comparing s2 and s1:"<< "\ns2 == s1 yields " << (s2 == s1 ? "true" : "faulse")<< "\ns2 != s1 yields " << (s2 != s1 ? "true" : "faulse")<< "\ns2 > s1 yields " << (s2 > s1 ? "true" : "faulse")<< "\ns2 < s1 yields " << (s2 < s1 ? "true" : "faulse")<< "\ns2 >= s1 yields " << (s2 >= s1 ? "true" : "faulse")<< "\ns2 <= s1 yields " << (s2 <= s1 ? "true" : "faulse");cout << "\n\nTesting s3.empty():" << endl;if (s3.empty()){cout << "s3 is empty;assigned s1 to s3;" << endl;s3 = s1;cout << "s3 is \"" << s3 << "\"";}cout << "\n\ns1 += s2 yields s1 = ";s1 += s2;cout << s1;cout << "\n\ns1 += \" to you\" yields" << endl;s1 += "to you";cout << "s1 = " << s1 << "\n\n";cout << "The substring of s1 starting ati location 0 for\n"<< "14 characters, s1.substr(0,14), is :\n"<< s1.substr(0, 14) << "\n\n";cout << "The substring of s1 starting at\n"<< "location 15, s1.substr(15), is:\n"<< s1.substr(15) << endl;string s4(s1);cout << "\ns4 = " << s4 << "\n\n";cout << "assigning s4 to s4" << endl;s4 = s4;cout << "s4 = " << s4 << endl;s1[0] = 'H';s1[6] = 'B';cout << "\ns1 after s1[0] = 'H' and s1[6]= 'B' is: "<< s1 << "\n\n";try{cout << "Attempt to assign 'd' to s1.at(30) yields:" << endl;s1.at(30) = 'd';}catch (out_of_range &ex){cout << "An exception occurred: " << ex.what() << endl;}}
阅读全文
0 0
- fig10.01.cpp
- fig10.3
- fig10.6
- cpp
- CPP
- CPP
- cpp
- cpp
- CPP
- CPP
- ClientSockThread.cpp&&ClientUrlThread.cpp
- cpp调用其他cpp
- ex34a.cpp&&ex34aDoc.cpp&&ex34aView.cpp
- MainFrm.cpp&&ServerThread.cpp&&SheetConfig.cpp
- CPP thread
- cpp->html
- CFaderWnd.cpp
- PasswordReminder.cpp
- 参数与非参的机器学习算法
- Linux下scrapy安装问题汇总
- hdu 6021 MG loves string 子集 容斥 循环节
- jenkins+weblogic/tomcat完全部署
- iOS中属性字符串转换成字符串
- fig10.01.cpp
- 第五章 分享内容到你的网站
- ${pageContext.request.contextPath}等EL表达式不能显示
- 自定义刷新(refreshview)样式
- 服务端指南
- 实用css效果
- JSP 实现 之 读取数据库显示图片
- linux中top和查看程序占用
- dp——vijos1322 解题