C语言问题 cin.get()
charch,a[20];cin.get(a,5);cin>>ch;cout<<a<<endl<<ch<<endl;如果输入的是12345,输出就变成1234回车5是不是...
char ch,a[20];cin.get(a,5);cin>>ch;cout<<a<<endl<<ch<<endl;
如果输入的是12345,输出就变成1234回车5
是不是在cin.get(a,5)的时候,只读取4个?为什么只读4个,程序是写5个,是不是最后一个是 \n?请具体讲解下,谢谢。还有,ratings 展开
如果输入的是12345,输出就变成1234回车5
是不是在cin.get(a,5)的时候,只读取4个?为什么只读4个,程序是写5个,是不是最后一个是 \n?请具体讲解下,谢谢。还有,ratings 展开
展开全部
cin.get ( char* s, streamsize n ) 函数的说明如下:
istream& get (char* s, streamsize n );
Extracts characters from the stream and stores them as a c-string into the array beginning at s. Characters are extracted until either (n - 1) characters have been extracted or the delimiting character '\n' is found. The extraction also stops if the end of file is reached in the input sequence or if an error occurs during the input operation.
意思是:可以从标准输入流中最多读取n-1个字符,存储到字符数组s中,而不是说最后一个是 \n
istream& get (char* s, streamsize n );
Extracts characters from the stream and stores them as a c-string into the array beginning at s. Characters are extracted until either (n - 1) characters have been extracted or the delimiting character '\n' is found. The extraction also stops if the end of file is reached in the input sequence or if an error occurs during the input operation.
意思是:可以从标准输入流中最多读取n-1个字符,存储到字符数组s中,而不是说最后一个是 \n
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询