Jump to content
  • Advertisement
Sign in to follow this  
derek_nofsinger

Issue with c2678 (String comparing) in VS2005

This topic is 3843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm currently working on upgrading code on a Visual Studio solution that I haven't created. I'm basically upgrading the code so that it will compile with Visual Studio 2005 and I'm stumped on a error with the VS2005 compiler: c22678: binary '!=' : no operator defined which takes a left-hand operand of type 'std::_String_iterator<_Elem,_Traits,_Alloc>' or there is no acceptable conversion) Am I right in using #include <string.h> (I haven't seen the bug go away with just <string>)? The bug appears on this line of code: if((buffer.end() - 1) != "\n") The "buffer" variable is a reference declared as type std::string I hope this will be enough information to provide for an answer. I can't copy the code or errors easily since the computer I'm working on isn't connected to a network. Any help is appreciated!

Share this post


Link to post
Share on other sites
Advertisement
"\n" is a C-string. You probably want '\n', which is a single character. You also probably want to dereference the iterator, which makes the line:
if(*(buffer.end() - 1) != '\n')

Share this post


Link to post
Share on other sites
^ Like he said.

Also, the last letter of a string is simply the first letter looking at it backwards, so you could also use .rbegin() and avoid the arithmetic.

Share this post


Link to post
Share on other sites
Thanks guys! :)

But I have another compiler error on the line after that. Here's what the code looks like now.:

if(*(buffer.end() - 1) != '\n')
buffer.append('\n'); // Getting error c2664

c2664: cannot convert parameter 1 ("buffer") from 'char' to 'const std::string &'

(Highly shortened message to get it on the computer that is connected to the network)

Again buffer is declared (as a parameter of a function) as std::string &

If I can get some more help on this issue, it would be great!

Share this post


Link to post
Share on other sites
Quote:
Original post by derek_nofsinger
Thanks guys! :)

But I have another compiler error on the line after that. Here's what the code looks like now.:

if(*(buffer.end() - 1) != '\n')
buffer.append('\n'); // Getting error c2664

c2664: cannot convert parameter 1 ("buffer") from 'char' to 'const std::string &'

(Highly shortened message to get it on the computer that is connected to the network)

Again buffer is declared (as a parameter of a function) as std::string &

If I can get some more help on this issue, it would be great!
Check the documentation for std::basic_string; I think you'll find that there is no append() function with that particular signature.

In any case, I think += is defined for characters, so I would just write:
if (buffer.empty() || *(buffer.rbegin()) != '\n') { buffer += '\n'; }
Better yet would be to just use (e.g.) boost::ends_with().

[Edited by - jyk on February 8, 2008 2:09:33 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!