0

I am trying to replace a string in a vector of structs.

struct Song { string artist; string title; string album; double m_price; string year; size_t length; }; vector<Song> c_collection; 

Then I used this loop to replace a string "[None]" in 'album' with 6 spaces:

for (auto& c : c_collection) { std::replace(c.album.begin(), c.album.end(), string("[None]"), string(" ")); } 

Compiler shows an error which says:

 "cannot convert from 'const_Ty' to 'char' with [ _Ty=std::string ]". 

What did i do wrong?

5
  • Your error has nothing to do with the vector, or the struct. Your replace is wrong. See the dupe for some ways of doing that. Commented Jul 19, 2020 at 19:58
  • Also, please stop posting duplicate questions. Commented Jul 19, 2020 at 20:00
  • You are trying to compare each char in album with a string [None]. You need to compare album as a string with [None]. Commented Jul 19, 2020 at 20:02
  • @stackoverblown How can I do this? Commented Jul 19, 2020 at 20:04
  • Directly compare the two like if ( c.album == "[None]" ) c.album = std::string(" "); Commented Jul 19, 2020 at 20:23

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.