标签:
*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 }
标签:
原文地址:http://www.cnblogs.com/grey-qisen/p/4759614.html