C-style 字符串小示例

    xiaoxiao2021-03-29  31

    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))

    转载请注明原文地址: https://ju.6miu.com/read-664828.html

    最新回复(0)