boost::split leaves empty tokens at the beginning and end of string - is this desired behaviour?

前端 未结 3 730
暗喜
暗喜 2021-01-02 06:32

Since I couldn\'t find anything on this in the documentation, I thought I ask it here. I have the following program (C++11):

#include  
#inc         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 07:00

    The behavior is intentional, because you could recreate the string (complete with starting and trailing spaces) from the split version. Boost doesn't know if that whitespace is significant or not to you (it might be, as some file formats, for example, might force leading spaces/specific space counts).

    You should trim_if or trim as you are if you do need to remove leading/trailing spaces.

提交回复
热议问题