C++中getline(cin,string)最多一行能读取多少个字符 5
3个回答
展开全部
这个不是固定的长度,刚开始会初始化一个长度,但是当行超出这个长度的时候,getline会重新给这个buffer长度进行开辟,来适应变长的行。请参看考我给出来链接中的英文说明部分。
“ If *lineptr is NULL, the getline() routine will allocate a buffer for containing the line, which must be freed by the user program. Alternatively, before calling getline(), *lineptr can contain a pointer to a malloc()-allocated buffer *n bytes in size. If the buffer is not large enough to hold the line read in, getline() resizes the buffer to fit with realloc()(), updating *lineptr and *n as necessary. In either case, on a successfulll, *lineptr and *n will be updated to reflect the buffer address and size respectively.”
“ If *lineptr is NULL, the getline() routine will allocate a buffer for containing the line, which must be freed by the user program. Alternatively, before calling getline(), *lineptr can contain a pointer to a malloc()-allocated buffer *n bytes in size. If the buffer is not large enough to hold the line read in, getline() resizes the buffer to fit with realloc()(), updating *lineptr and *n as necessary. In either case, on a successfulll, *lineptr and *n will be updated to reflect the buffer address and size respectively.”
参考资料: http://linux.chinaunix.net/techdoc/develop/2007/01/04/947366.shtml
展开全部
为什么不可以呢 getline是遇到换行符\n或者结束符EOF才结束的 要是希望读取100个以上 可以屏蔽到换行符就可以了 不知道楼主希望做什么 是一次读取100个字符还是 一次读取一样 毕竟一样的概念就已经代表了存在换行符的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询