Exercise 4.31:
编写程序从标准输入设备读入字符串,并把该串存放在字 符数组中。描述你的程序如何处理可变长的输入。提供比 你分配的数组长度长的字符串数据测试你的程序。
string in_str; const size_t str_size = 10; char result_size[str_size+1]; cout<<"Enter a string<="<<str_size<<"characters"<<endl; cin>>in_str; size_t len = strlen(in_str.c_str()); if(len > str_size) { len = str_size; cout<<"String is longer than "<<str_size<<"characters and is stored only"<<str_size<<"characters"<<endl; } strncpy(result_size,in_str.c_str(),len); result_size[len+1] = '