网站大量收购独家精品文档,联系QQ:2885784924

C++Primer习题(第三章附答案) .pdf

  1. 1、本文档共33页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C++Primer习题(第三章附答案) 练习3.1 略 练习 3. 2 编写⼀段程序从标准输⼊中⼀次读⼊⼀整⾏,然后修改程序使其⼀次读⼊⼀个词。 #include iostream #includestring using namespace std ; 使⽤ ⼀次读⼊⼀整⾏,回车结束 // getline int main() { string line ; cout please enter your line ,even space endl; 循环读取, 结束 while (getline(cin, line)) // Ctrl+c cout line endl; return 0; } #include iostream #includestring using namespace std ; 使⽤ ⼀次读⼊⼀单词,空⽩结束 // cin int main() { string word ; cout please enter your word ,not space endl; 循环读取, 结束 while (cinword) // Ctrl+c cout word endl; return 0; } 练习3.3 请说明string类的输⼊运算符和getline函数是如何分别处理空⽩字符的 #includeiostream #includestring using namespace std ; int main() { string word, line ; cout please select the way to read the string endl; cout 1 means read string by word endl; cout 2 means read string by line endl; char ch ; cin ch ; if (ch == 1) { cout please enter string : welcome to c++ family endl; cin word ; cout system read the string is : word endl; } else if (ch == 2) { cout please enter string : welcome to c++ family endl; getline(cin, line); cout system read the string is : line endl; } else { cout input error,please try again endl; } return 0; } 练习3.4 编写⼀段程序读⼊两个字符窜,⽐较其是否相等并输出结果。结果不相等,输出较⼤的那个字符串。改写上述程序,⽐较输⼊的两 个字符串是否等长,如果不等长,输出长度较⼤的那个字符串。 #includeiostream #includestring using namespace std ; int main() { string word1, word2 ; cout please enter two strings endl; cin word1 word2 ; if (word1 == word2) { cout word1 endl; } else if (word1word2) { cout word1 endl; } else { cout word2 endl; } return 0; } #includeiostream #includestring using namespace std ; int main() { string word1, word2 ; cout please ent

文档评论(0)

. + 关注
官方认证
内容提供者

专注于职业教育考试,学历提升。

版权声明书
用户编号:8032132030000054
认证主体社旗县清显文具店
IP属地河南
统一社会信用代码/组织机构代码
92411327MA45REK87Q

1亿VIP精品文档

相关文档