码迷,mamicode.com
首页 > 其他好文 > 详细

#4 复合类型

时间:2015-08-26 10:37:15      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

*1:C++接受输入字符串

 1 /* Author : grey_qisen */
 2 // instr1.cpp -- reading more than one string  
 3 
 4 #include<iostream>
 5 int main(){
 6     using namespace std;
 7     const int ArSize = 20;
 8     char name[ArSize];
 9     char dessert[ArSize];
10     
11     cout << "Enter your name:\n";
12     cin  >> name;
13     cout << "Enter your favorite dessert:\n";
14     cin  >> dessert;
15     cout << "I have some delicious " << dessert;
16     cout << " for you, " << name << ".\n"; 
17 
18     return 0;
19 }

 

 1 /* Author : grey_qisen */
 2 // instr2.cpp -- reading more than one word with getline
 3 #include<iostream>
 4 int main(){
 5     using namespace std;
 6     const int ArSize = 20;
 7     char name[ArSize];
 8     char dessert[ArSize];
 9     
10     cout << "Enter your name:\n";
11     cin.getline(name,ArSize);        // reads through newline
12     cout << "Enter your favorite dessert:\n";
13     cin.getline(dessert,ArSize);
14     cout << "I have some delicious " << dessert;
15     cout << " for you, " << name << ".\n";
16 
17     return 0;
18 }

 

#4 复合类型

标签:

原文地址:http://www.cnblogs.com/grey-qisen/p/4759614.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!