J1awexr 2022-04-30 23:32 采纳率: 0%
浏览 33

关于算法分析与设计的思考

问题遇到的现象和发生背景:在课本的序章讲解STL string 类的例题中出现了如下伪代码:

    char cstr[] = "China!Great Wall";
    string s1(cstr);                //s1:China!Great Wall
    string s2(s1);                //s2:China!Great Wall
    string s3(cstr, 7, 11);    //s3:Great Wall
    string s4(cstr, 6);            //s4:China!I
    string s5(5, 'A');            //s5:AAAAA
}

然后我发现s4的结果 并不是明白,所以我去带到ide环境

#include<iostream>
#include<string>

using namespace std;

void main(){

    char cstr[] = "China!Great Wall";
    string s1(cstr);        //s1:China!Great Wall
    string s2(s1);            //s2:China!Great Wall
    string s3(cstr, 7, 11); //s3:Great Wall
    string s4(cstr, 6);        //s4:China!
    string s5(5, 'A');        //s5:AAAAA
}

运行结果及报错内容

img

我想要达到的结果:理解s4的结果以及解决代码问题

  • 写回答

2条回答 默认 最新

  • 真相重于对错 2022-05-01 08:31
    关注

    报什么错???

    评论

报告相同问题?

问题事件

  • 创建了问题 4月30日