V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
haikea
V2EX  ›  C++

改了一行代码居然引起了改变了程序,不理解请大佬开导

  •  
  •   haikea · 2019-08-30 17:12:01 +08:00 · 3686 次点击
    这是一个创建于 1672 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在学习谷歌的开源浏览器 Cef 框架,

    //std::string old_overflow;
    if (max_write < str_size) {
          overflow_ += std::string(str + max_write, str_size - max_write);
    }
    

    然后我改成了这样

    //std::string old_overflow;
    if (max_write < str_size) {
          std::string test = std::string(str + max_write, str_size - max_write);
          overflow_ += test;
    }
    

    结果在打开网页时,往来的代码没有问题,我改的就要反复刷新好几次才会出现网页,我也就是把一行代码拆开写了,为啥会这样?

    7 条回复    2019-08-30 17:43:12 +08:00
    phpfpm
        1
    phpfpm  
       2019-08-30 17:23:23 +08:00
    你没分配空间?
    ysc3839
        2
    ysc3839  
       2019-08-30 17:28:16 +08:00 via Android
    这段代码在哪里的?
    haikea
        3
    haikea  
    OP
       2019-08-30 17:33:45 +08:00
    @phpfpm 定义字符串时赋值也要分配空间吗
    haikea
        4
    haikea  
    OP
       2019-08-30 17:34:25 +08:00
    @ysc3839 第一段谷歌 cef3 的示例代码,第二段我改了一行
    ysc3839
        5
    ysc3839  
       2019-08-30 17:38:02 +08:00 via Android
    @haikea “第一段谷歌 cef3 的示例代码”到底是什么……能给个链接吗?
    xuyaomin
        6
    xuyaomin  
       2019-08-30 17:41:10 +08:00
    这个改动不会造成你说的那种影响
    maichael
        7
    maichael  
       2019-08-30 17:43:12 +08:00
    你把这个改动改回去,然后再随便改另外一个地方,再测试一遍看看效果。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   982 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:09 · PVG 06:09 · LAX 15:09 · JFK 18:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.