| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2178 人关注过本帖
标题:有代码不理解,求大佬帮忙!
取消只看楼主 加入收藏
a75692074
Rank: 1
等 级:新手上路
威 望:1
帖 子:48
专家分:0
注 册:2018-7-20
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:1 
有代码不理解,求大佬帮忙!
程序代码:
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int main()
{
    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);
    cout << "You entered: " << charr << endl;
    cout << "Enter another line of text:\n";
    getline(cin, str);
    cout << "You entered: " << str << endl;
    cout << "Length of string in charr after input: "
         << strlen(charr) << endl;
    cout << "Length of string in str after input: "
         << str.size() << endl;
    return 0;
}


为什么这一段

   
cout << "Length of string in charr before input: "
     << strlen(charr) << endl;


结果是

Length of string in charr before input: 3


求大佬帮忙解释一下
搜索更多相关主题的帖子: str string cout Length input 
2018-08-28 09:59
a75692074
Rank: 1
等 级:新手上路
威 望:1
帖 子:48
专家分:0
注 册:2018-7-20
收藏
得分:0 
回复 2楼 rjsp
但它可以打印结果,是3,我不知道为什么
2018-08-29 11:55
快速回复:有代码不理解,求大佬帮忙!
数据加载中...
 
   



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

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