V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
haikea
V2EX  ›  C++

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

  •  
  •   haikea · Aug 30, 2019 · 4564 views
    This topic created in 2439 days ago, the information mentioned may be changed or developed.

    最近在学习谷歌的开源浏览器 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 replies    2019-08-30 17:43:12 +08:00
    phpfpm
        1
    phpfpm  
       Aug 30, 2019
    你没分配空间?
    ysc3839
        2
    ysc3839  
       Aug 30, 2019 via Android
    这段代码在哪里的?
    haikea
        3
    haikea  
    OP
       Aug 30, 2019
    @phpfpm 定义字符串时赋值也要分配空间吗
    haikea
        4
    haikea  
    OP
       Aug 30, 2019
    @ysc3839 第一段谷歌 cef3 的示例代码,第二段我改了一行
    ysc3839
        5
    ysc3839  
       Aug 30, 2019 via Android
    @haikea “第一段谷歌 cef3 的示例代码”到底是什么……能给个链接吗?
    xuyaomin
        6
    xuyaomin  
       Aug 30, 2019
    这个改动不会造成你说的那种影响
    maichael
        7
    maichael  
       Aug 30, 2019
    你把这个改动改回去,然后再随便改另外一个地方,再测试一遍看看效果。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2806 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 08:18 · PVG 16:18 · LAX 01:18 · JFK 04:18
    ♥ Do have faith in what you're doing.