error: invalid operands of types ‘const char*’ and ‘const char [4]’ to binary ‘operator+’

Phong Cao phngcv at gmail.com
Fri Jul 1 02:26:02 CEST 2011


Hello everybody,

I am trying to use TagLib to extract tags from a stream and store it in a
std::string. Here is the function I used:

void TopWin::insert_tag_on_db(std::vector<std::string> &filenames) {
  for (std::vector<std::string>::iterator iter = filenames.begin(); iter !=
filenames.end(); ++iter) {
    TagLib::FileRef file((*iter).c_str());

    if (!file.isNull() && file.tag()) {
      TagLib::Tag *tag = file.tag();
      TagLib::AudioProperties *properties = file.audioProperties();

      int seconds = properties->length() % 60;
      int minutes = (properties->length() - seconds) / 60;

      //error occurs here
      std::string insert = "INSERT INTO SongList (track, name, genre,
artist, album, time, uri) values (" + tag->track() + ", '" + tag->title() +
"', '" + tag->genre() + "', '" + tag->artist() + "', '" + tag->album() + "',
'" + minutes + ":" + seconds + "', '" + *iter + "');";
    }
  }
}

However, the program was not compiled. g++ reported an error:

/home/phongcao/dingo/topwin.cc:16: error: invalid operands of types ‘const
char*’ and ‘const char [4]’ to binary ‘operator+’

I have read the TagLib documentation and it said that the TagLib's return
type is TagLib::String. What I do not understand here is whether
TagLib::String is similar to std::string or char*? If it is similar to
std::string then what is the source of the above error?

I guess the source of the error is that I was trying to concatenate
tag->title(), tag->track(), etc... (which may have types char*, since I do
not know TagLib::String is a CString or a std::string) to a string literal.
Can you guys suggest a solution to fix this error?


Thank you for reading my message! Have a good day!


Best regards,

-- 
Phong V. Cao
phngcv at gmail.com
caoph at rider.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/taglib-devel/attachments/20110630/8f403eb8/attachment.htm 


More information about the taglib-devel mailing list