标题:20位的数组,为什么输出是27(31)呢?
取消只看楼主
lxfeng1988
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-8-4
结帖率:100%
已结贴  问题点数:16 回复次数:1 
20位的数组,为什么输出是27(31)呢?
程序清单:
//strtype4.cpp--line input
#include<iostream>
#include<string>  //make string class available
#include<cstring>  //C-style string library
int main()
{
    using namespace std;
    char charr[20];
    string str;
    cout<<"Length of string in charr before input: "
        <<strlen(charr)<<endl;
    cout<<"Length of string in str before input: "
        <<str.size()<<endl;
    cout<<"Enter a line of text:\n";
    cin.getline(charr,20);  //indicate maximum length
    cout<<"You entered: "<<charr<<endl;
    cout<<"Enter another line of text:\n";
    getline(cin,str);  //cin now an argument;no length specifier
    cout<<"Length of string in charr after input: "
        <<strlen(charr)<<endl;
    cout<<"Length of string in str after input: "
        <<str.size()<<endl;
    return 0;
}
请问输出结果“Length of string in charr before input”是什么(我觉得应该是20)呢?
书上给出的结果是27
而我敲进编译器给出的结果是31
求大神指导!!!
搜索更多相关主题的帖子: available indicate include before Enter 
2014-01-01 11:53
lxfeng1988
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-8-4
得分:0 
回复 2楼 yuccn
明白了,谢谢。
2014-01-03 08:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-425979-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.116451 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved