新人关于c++中cin.get的一个疑惑

第一个字符总是被换成了‘0’;这是什么原因啊。

#include "stdafx.h"
#include
using namespace std;

int main()
{
char a[10], b[10], c;
cin.get(a, 1, ';');
cout << int(a[0]);
system("pause");
return 0;
}

cin.get(a, 1, ';');这句的意思是 输入遇到 ';' 就停止输入了,但是你这儿明显是输入了其他数,然后没有地方存“;”结束符了,如果你把这句中1改为2改为,先输入1一个数,在输入结束符,那就没问题了

http://blog.csdn.net/xuexiacm/article/details/8101859这个讲的很详细

cin.get(字符指针, 字符个数n, 终止字符)
其作用是从输入流中读取n-1个字符,赋给指定的字符数组(或字符指针指向的数组),如果在读取n-1个字符之前遇到指定的终止字符,则提前结束读取。

也就是读n-1个字符,然后在第n个字符位置写入'\0',你每次打印的数字0其实就是这个字符

cin.get(字符指针, 字符个数n, 终止字符)
从输入流中读的是n个字符
1、写入时最多写n-1个字符,在最后写入'\0'
2、如果在n个字符中发现终止字符,就写入终止字符前的字符,在最后写入'\0'。

cin.get(a, 1, ';');
根据上边所述1,a[0]始终写入的是'\0'

 int main( ) 
{
   char c[10];

   c[0] = cin.get( );
   cin.get( c[1] );
   cin.get( &c[2],3 );
   cin.get( &c[4], 4, '7' );

   cout << c << endl;
}
 int_type get();
basic_istream<Elem, Tr>& get(
    Elem& _Ch
);
basic_istream<Elem, Tr>& get(
        Elem *_Str,
       streamsize _Count
);
basic_istream<Elem, Tr>& get(
        Elem *_Str,
        streamsize _Count,
        Elem _Delim
);
basic_istream<Elem, Tr>& get(
        basic_streambuf<Elem, Tr>& _Strbuf
);
basic_istream<Elem, Tr>& get(
        basic_streambuf<Elem, Tr>& _Strbuf,
        Elem _Delim
);

MSDN 的解释。。

onepiece09 说的是对的 如果指定取得的数量是1那么只会写入\0