amiwrong123
V2EX  ›  C++

为毛 stringstream 遇到 bitset 打印结果很奇怪?

  •  
  •   amiwrong123 · Mar 2, 2020 · 2301 views
    This topic created in 2288 days ago, the information mentioned may be changed or developed.
    	bitset<4> bs;
    	bs[1] = 1;
    	std::stringstream tempStr;
    	tempStr << bs;
    	string temps = tempStr.str();
    
    
    3WAisP.png

    debug 结果却是这样, 那个 string 应该是 0100 的,现在却是 0010 了。

    3 replies    2020-03-02 16:53:54 +08:00
    codehz
        1
    codehz  
       Mar 2, 2020   ❤️ 2
    因为 bitset 的 index 是从后往前算的(
    codehz
        2
    codehz  
       Mar 2, 2020
    类比数字,个位十位百位是怎么叫的(
    amiwrong123
        3
    amiwrong123  
    OP
       Mar 2, 2020
    @codehz
    好吧,原来如此
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   963 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 18:26 · PVG 02:26 · LAX 11:26 · JFK 14:26
    ♥ Do have faith in what you're doing.