C++编程实战:从基础到应用
在C++编程中,我们会遇到各种各样的问题和需求。下面将通过一系列的示例代码和练习,深入探讨C++编程的多个方面。
1. 输入姓名并输出问候语
以下代码实现了让用户输入姓名,并根据姓名长度输出相应问候语的功能。
const int nm_size = 128;
char user_name[nm_size];
cout << "Please enter your name: ";
cin >> setw(nm_size) >> user_name;
switch (strlen(user_name))
{
// same case labels for 0, 1
case 127:
// maybe string was truncated by setw()
cout << "That is a very big name, indeed -- "
<< "we may have needed to shorten it!\n"
<< "In any case,\n";
// no break -- we fall through ...
default:
// the 127 case drops through to here -- no break
cout << "Hello, " <
超级会员免费看
订阅专栏 解锁全文
5万+

被折叠的 条评论
为什么被折叠?



