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

Kyle gonemad at gmail.com
Fri Jul 1 02:55:47 CEST 2011


You can view the source to the string class. I think its tstring.h or
something. From what I remember it doesn't support the + operation like you
are using.  I'd just store artist album etc in a stdstring first before
concatinating
On Jun 30, 2011 8:26 PM, "Phong Cao" <phngcv at gmail.com> wrote:
> 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/03201eaa/attachment.htm 


More information about the taglib-devel mailing list