Jecho

导航

C-style 字符串小示例

const int n_size=127;

 char user_name[n_size];

 cout<<"enter your name:"<<endl;

 cin>>setw(n_size)>>user_name;

  //setw();将字符串限制在n_size-1中,若n_size为3,这里如果输进uirtt 只会保留ui(还有一个结束字符),最后一个

 //是字符串结束符 (#include <iomanip>)

 cout<<user_name;

 switch (strlen (user_name))

posted on 2013-05-10 11:08  Jecho  阅读(202)  评论(0编辑  收藏  举报