function substr() help

c++.....in my program i have 3 string-s (string houses,string ink,string buildings)and i must add function substr()... In the program i need to add a function that receives a parameter of type string. The task function is that the resulting string is inserted characters '=' to split a string of characters into subsets 5 letters long. If you come to the end and no more letters after the equal sign is not added. The function should not display anything but the resulting string is returned as a result. Example:
A function recive: "housesinkbuildings"
The function returns: "house=sinkb=uildi=ngs"
in The main program Add call of this function so that it is specified as a parameter string consists houses,ik, buildings.
i do the hole program but this thing, function i dont know very vel,,,beginer,,,please help
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <string>

std::string insert_seperator( std::string str, char sep = '=', std::size_t gap = 5 )
{
    std::string result ;
    std::size_t cnt = 0 ;
    for( char c : str )
    {
        if( cnt > 0 && cnt%gap == 0 ) result += sep ;
        result += c ;
        ++cnt ;
    }

    return result ;
}

http://coliru.stacked-crooked.com/a/3a8ef546b0398749
thanks man (Y)
Topic archived. No new replies allowed.