开发者

std::sort on std::vector<std::string>

I have a std::vector&开发者_开发问答lt;std::string> which would contain numbers and characters (single char). I would want to have numbers sorted first followed by the characters...so I have a jumbled up vector of strings as an input and after sort I want it like 1,2,3,5,7,9,10,A,B,C,D. But I guess sort also compares the sizes of the inputs, and hence if my vector has numbers of different lengths, I am getting a wrong output. For instance, doing an std::sort (vec.begin(),vec.end()) on 9,4,5,2,10,11,A,D,B,E,C returns 10,11,2,4,5,9,A,B,C,D,E.

How do I rectify my mistake and what am I missing?

Thank you,

Sayan


Write a non-lexicographical comparison routine and pass it along with the iterators to std::sort.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜