amiwrong123
V2EX  ›  C++

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

  •  
  •   amiwrong123 · Mar 2, 2020 · 2588 views
    This topic created in 2444 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
    codehz
    Mar 2, 2020❤️2
    1
    因为 bitset 的 index 是从后往前算的(
    codehz
    codehz
    Mar 2, 2020
    2
    类比数字,个位十位百位是怎么叫的(
    amiwrong123
    amiwrong123
    OP
    Mar 2, 2020
    3
    @codehz
    好吧,原来如此
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4203 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 09:19 · PVG 17:19 · LAX 01:19 · JFK 04:19
    ♥ Do have faith in what you're doing.