Newbie hexadecimal question

Discussion in 'C++' started by Jim Lake, Nov 28, 2004.

  1. Jim Lake

    Jim Lake Guest

    I'm creating a string of hex characters and I have an unsigned char
    value of 00 assigned to the name IS.
    I try m_strResp += IS to append the hex 00 to the hex characters
    already in m_strResp and I get a C2593 compile error (error
    C2593: 'operator +=' is ambiguous). I can see where adding 0 to
    something is ambiguous but I'm not trying to do arithmetic. I'm
    trying to create a string of hex characters.
    Any suggestions?
    Thanks!
     
    Jim Lake, Nov 28, 2004
    #1
    1. Advertising

  2. Jim Lake

    ajk Guest

    On 28 Nov 2004 05:43:44 -0800, (Jim Lake) wrote:

    >I'm creating a string of hex characters and I have an unsigned char
    >value of 00 assigned to the name IS.
    >I try m_strResp += IS to append the hex 00 to the hex characters
    >already in m_strResp and I get a C2593 compile error (error
    >C2593: 'operator +=' is ambiguous). I can see where adding 0 to
    >something is ambiguous but I'm not trying to do arithmetic. I'm
    >trying to create a string of hex characters.
    >Any suggestions?
    >Thanks!


    you could try using stringstream instead:

    #include <sstream>
    #include <iomanip>

    ....

    stringstream ss;
    int somevalue = 0;
    ss << hex << somevalue;

    cout << ss.str() << endl;

    /ajk
     
    ajk, Nov 28, 2004
    #2
    1. Advertising

  3. * Jim Lake:
    > I'm creating a string of hex characters and I have an unsigned char
    > value of 00


    No, you don't.

    > assigned to the name IS.


    No, you don't. That is at best a macro definition. Don't use
    macros.


    > I try m_strResp += IS


    Don't use mangled names, use meaningful names.


    > to append the hex 00 to the hex characters
    > already in m_strResp and I get a C2593 compile error (error
    > C2593: 'operator +=' is ambiguous).


    The following code reproduces your problem:

    #include <string>

    int main()
    {
    std::string s;

    s += 0;
    }

    Always post code that reproduces the problem. Copy and paste
    the code. Don't type it in.


    > I can see where adding 0 to
    > something is ambiguous but I'm not trying to do arithmetic. I'm
    > trying to create a string of hex characters.
    > Any suggestions?


    As already stated: don't use macros. A macro does not have a type.
    And that's the direct cause of your problem.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Nov 28, 2004
    #3
  4. Jim Lake

    Jim Lake Guest

    #include <string>

    int main()
    {
    std::string s;

    s += 0;
    }

    c:\documents and settings\administrator.the_domain\my documents\my
    projects\test.cpp(6) : error C2593: 'operator +=' is ambiguous

    c:\documents and settings\administrator.the_domain\my documents\my
    projects\test.cpp(7) : warning C4508: 'main' : function should return
    a value; 'void' return type assumed

    How is this adding a hex 00 to a string (group) of hex characters?

    I'm looking to add a hex 00 to this: FF FA

    I want this-->FF FA to become this--> FF FA 00

    (Alf P. Steinbach) wrote in message news:<>...
    > * Jim Lake:
    > > I'm creating a string of hex characters and I have an unsigned char
    > > value of 00

    >
    > No, you don't.
    >
    > > assigned to the name IS.

    >
    > No, you don't. That is at best a macro definition. Don't use
    > macros.
    >
    >
    > > I try m_strResp += IS

    >
    > Don't use mangled names, use meaningful names.
    >
    >
    > > to append the hex 00 to the hex characters
    > > already in m_strResp and I get a C2593 compile error (error
    > > C2593: 'operator +=' is ambiguous).

    >
    > The following code reproduces your problem:
    >
    > #include <string>
    >
    > int main()
    > {
    > std::string s;
    >
    > s += 0;
    > }
    >
    > Always post code that reproduces the problem. Copy and paste
    > the code. Don't type it in.
    >
    >
    > > I can see where adding 0 to
    > > something is ambiguous but I'm not trying to do arithmetic. I'm
    > > trying to create a string of hex characters.
    > > Any suggestions?

    >
    > As already stated: don't use macros. A macro does not have a type.
    > And that's the direct cause of your problem.
     
    Jim Lake, Nov 28, 2004
    #4
  5. * Jim Lake:
    > [top-posting]


    Don't top post. Read the FAQ. I have corrected the top-posting
    here, but for best chance of useful answers: following usual posting
    guidelines such as not top-posting, including relevant code, etc.


    * Jim Lake:
    > #include <string>
    >
    > int main()
    > {
    > std::string s;
    >
    > s += 0;
    > }
    >
    > c:\documents and settings\administrator.the_domain\my documents\my
    > projects\test.cpp(6) : error C2593: 'operator +=' is ambiguous


    This is the error message you claimed, so the error seems to have
    been successfully reproduced.


    > c:\documents and settings\administrator.the_domain\my documents\my
    > projects\test.cpp(7) : warning C4508: 'main' : function should return
    > a value; 'void' return type assumed


    This is an incorrect warning, which means you're using an old compiler.

    Try g++.

    It's free.


    > How is this adding a hex 00 to a string (group) of hex characters?


    It isn't, it's what you most probably did.


    > I'm looking to add a hex 00 to this: FF FA
    >
    > I want this-->FF FA to become this--> FF FA 00


    To add a string to the end of a std::string you can use the "+="
    operator, like this:


    std::string s = "FF FA";

    s += " 00";

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Nov 28, 2004
    #5
  6. Jim Lake

    Howard Guest

    "Alf P. Steinbach" <> wrote in message
    news:...
    >> #include <string>
    >>
    >> int main()
    >> {
    >> std::string s;
    >>
    >> s += 0;
    >> }
    >>
    >> c:\documents and settings\administrator.the_domain\my documents\my
    >> projects\test.cpp(6) : error C2593: 'operator +=' is ambiguous

    >
    > This is the error message you claimed, so the error seems to have
    > been successfully reproduced.
    >
    >
    >> c:\documents and settings\administrator.the_domain\my documents\my
    >> projects\test.cpp(7) : warning C4508: 'main' : function should return
    >> a value; 'void' return type assumed

    >
    > This is an incorrect warning, which means you're using an old compiler.
    >
    > Try g++.
    >
    > It's free.
    >
    >
    >> How is this adding a hex 00 to a string (group) of hex characters?

    >
    > It isn't, it's what you most probably did.
    >
    >
    >> I'm looking to add a hex 00 to this: FF FA
    >>
    >> I want this-->FF FA to become this--> FF FA 00

    >
    > To add a string to the end of a std::string you can use the "+="
    > operator, like this:
    >
    >
    > std::string s = "FF FA";
    >
    > s += " 00";
    >


    This is assuming, of course, that Jim, meant that he had a string that
    contains "FF FA" when he said that.

    It *may* be that what he had was a string that contained two unsigned char
    values where the first unsigned char had the hex value FF and the second had
    the hex value FA. In that case, appending the hex value 00 (which is just
    the single unsigned char with value zero) would be a different task from
    appending the string " 00" (which is three unsigned char's: a space
    character, followed by two "0" characters).

    Jim, can you please clarify which of the above two meanings you had in mind
    when you said you had a "string of hex characters"?

    -Howard
     
    Howard, Nov 29, 2004
    #6
  7. Jim Lake

    Old Wolf Guest

    "Howard" <> wrote
    > "Alf P. Steinbach" <> wrote:
    > > Jim wrote:
    > >> I'm looking to add a hex 00 to this: FF FA
    > >>
    > >> I want this-->FF FA to become this--> FF FA 00

    > >
    > > To add a string to the end of a std::string you can use the "+="
    > > operator, like this:
    > >
    > > std::string s = "FF FA";
    > > s += " 00";

    >
    > This is assuming, of course, that Jim, meant that he had a string that
    > contains "FF FA" when he said that.
    >
    > It *may* be that what he had was a string that contained two
    > unsigned char values where the first unsigned char had the hex
    > value FF and the second had the hex value FA.


    Unlikely - on most systems, char is 8-bit and signed,
    so a std::string (or a char array) can't contain FF and FA.

    Of course, it's hard to know when the guy can't be bothered
    posting any code.
     
    Old Wolf, Nov 30, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dmitry Bond.

    Hexadecimal formatting with leading zeros?!

    Dmitry Bond., Oct 13, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,047
    Oliver Sturm
    Oct 13, 2005
  2. Victor Hannak
    Replies:
    0
    Views:
    7,479
    Victor Hannak
    Feb 20, 2004
  3. Sylvain Munaut
    Replies:
    2
    Views:
    2,184
    Sylvain Munaut
    Dec 22, 2004
  4. DSKR
    Replies:
    5
    Views:
    552
    Darrell Grainger
    Jun 8, 2004
  5. Massi
    Replies:
    1
    Views:
    409
    JimLewis
    Apr 29, 2009
Loading...

Share This Page