How to use string.substr() function?

后端 未结 7 511
夕颜
夕颜 2020-11-29 06:40

I want to make a program that will read some number in string format and output it like this: if the number is 12345 it should then output 12 23 34 45 . I tried using the su

7条回答
  •  醉酒成梦
    2020-11-29 06:49

    Possible solution with string_view

    void do_it_with_string_view( void )
    {
        std::string a { "12345" };
        for ( std::string_view v { a }; v.size() - 1; v.remove_prefix( 1 ) )
            std::cout << v.substr( 0, 2 ) << " ";
        std::cout << std::endl;
    }
    

提交回复
热议问题