http://www.cnblogs.com/wanghao111/archive/2009/09/05/1560822.html

 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 
 5 
 6 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 7 
 8 int main(int argc, char** argv) {
 9     
10     string s;
11     char p[10];
12     char q[10];
13 
14     //cin.getline(p,4);//最大只能接受3个字符,自动在末尾加上'\0' 
15     cout<<"p="<<p<<endl;
16     
17     cin.getline(q,3,'\0');//输入字符串以'\0' 结尾 ,大只能接受3个字符
18     cout<<"q="<<q<<endl;
19     
20 
21     
22     getline(cin,s);
23     cout<<"s"<<s<<endl;
24 
25     cout<<"p="<<p<<endl; 
26     cout<<"q="<<q<<endl; 
27     cout<<"s"<<s<<endl;
28     return 0;
29 }

 

posted on 2016-09-08 09:53  人生一世,草木一秋。  阅读(20)  评论(0编辑  收藏  举报