Vector modification of strings

I am in a beginning c++ course and we never covered vectors, but I am trying to learn to do things with vectors instead of multidimensional arrays.

I get a error no matching function for call 'replace'.

Also how would I improve this method to make sure it only removes the part of the string of the 2nd vector that contains a , within it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 // delete duplicate names using set_intersection operator after first
    // unique name for the first two white space or until '
    for(int i = 0; i < newModified.music.size();i++)
    {
        for(int j = i+1; j < newModified.music.size(); j++)
        {
            vector<string> similarity;
            vector<string>::iterator pos;
            set_intersection(newModified.music[i].begin(),newModified.music[i].end(),newModified.music[j].begin(),newModified.music[j].end(),similarity);
            //if the similarities contain a ,
            pos = find(similarity.begin(), similarity.end(), ',');
            /*size_t foundit = similarity.find_first_of(","); */
            if (!pos->empty())
            {
                //delete the similarities in the second vector
                replace(newModified.music[j].begin(), newModified.music[j].end(), similarity, "");
            }
            else
            {
                //do nothing
            }
        }
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

int main ()
{
    std::vector<std::string> seq { "one", "zero", "two", "three", "zero", "four", "five" } ;
    const auto print = [&seq]
    { for( const auto& s : seq ) std::cout << s << ' ' ; std::cout << '\n' ; } ;
    print() ;

    // replace "zero" with "nil"
    const std::string zero = "zero" ;
    const std::string nil = "nil" ;
    std::replace( seq.begin(), seq.end(), zero, nil ) ;
    print() ;

    // replace strings which start with the character t with "ttttt" ;
    std::replace_if( seq.begin(), seq.end(),
                       []( const std::string& s ) { return !s.empty() && s[0] == 't' ; },
                       "ttttt" ) ;
    print() ;
}

http://ideone.com/CbZeCX
Topic archived. No new replies allowed.