wide string problem ...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SteveB

    #1

    wide string problem ...

    Hi

    I'm having major problems writing a function that converts a long
    value into a wide string !!! I'm more than likely going round in
    circles and not seeing the wood for the trees now but am frustreated
    just the same.

    My function looks like this:

    std::wstring CReportCreator: :SetEmpricalDef aults(const udtLONG&
    udtValue)
    {
    wstring ret = L"";
    ret = Utilities::Long ToStdWString(ud tValue.lngValue );
    return ret;

    }


    LongToStdWStrin g() is used elsewhere and works ok.

    My call is this:

    wstring strOut = SetEmpricalDefa ults(300L);

    and then:

    WCHAR xml[255];
    wsprintf(xml, L"<X><a=\"%s \" /></X>", strOut);

    wsprintf throws a scalar deleting desctructor exception.

    when i debug strOut show as "*300".

    does anyone know what the '*' represents at the beginning of the 300 ?

    does anyone know of a function that will return a unicode string from
    a long ? so far i've tried stringstreams and _ltow but always get the
    * in front of the 300 and wsprintf throws an exception ...

    many thanks

  • mimi

    #2
    Re: wide string problem ...

    On Mar 12, 5:27 pm, "SteveB" <s...@thebretts .co.ukwrote:
    Hi
    >
    I'm having major problems writing a function that converts a long
    value into a wide string !!! I'm more than likely going round in
    circles and not seeing the wood for the trees now but am frustreated
    just the same.
    >
    My function looks like this:
    >
    std::wstring CReportCreator: :SetEmpricalDef aults(const udtLONG&
    udtValue)
    {
    wstring ret = L"";
    ret = Utilities::Long ToStdWString(ud tValue.lngValue );
    return ret;
    >
    }
    >
    LongToStdWStrin g() is used elsewhere and works ok.
    >
    My call is this:
    >
    wstring strOut = SetEmpricalDefa ults(300L);
    >
    and then:
    >
    WCHAR xml[255];
    wsprintf(xml, L"<X><a=\"%s \" /></X>", strOut);
    wsprintf(xml, L"<X><a=\"%s \" /></X>", strOut.data()); //Should be
    this?
    >
    wsprintf throws a scalar deleting desctructor exception.
    >
    when i debug strOut show as "*300".
    >
    does anyone know what the '*' represents at the beginning of the 300 ?
    >
    does anyone know of a function that will return a unicode string from
    a long ? so far i've tried stringstreams and _ltow but always get the
    * in front of the 300 and wsprintf throws an exception ...
    >
    many thanks

    Comment

    • Alf P. Steinbach

      #3
      Re: wide string problem ...

      * SteveB:
      Hi
      >
      I'm having major problems writing a function that converts a long
      value into a wide string !!! I'm more than likely going round in
      circles and not seeing the wood for the trees now but am frustreated
      just the same.
      >
      My function looks like this:
      >
      std::wstring CReportCreator: :SetEmpricalDef aults(const udtLONG&
      udtValue)
      {
      wstring ret = L"";
      ret = Utilities::Long ToStdWString(ud tValue.lngValue );
      return ret;
      >
      >
      }

      Just a style issue, but make that

      {
      return Utilities::Long ToStdWString(ud tValue.lngValue );
      }


      LongToStdWStrin g() is used elsewhere and works ok.
      If you say so.

      My call is this:
      >
      wstring strOut = SetEmpricalDefa ults(300L);
      >
      and then:
      >
      WCHAR xml[255];
      wsprintf(xml, L"<X><a=\"%s \" /></X>", strOut);
      >
      wsprintf throws a scalar deleting desctructor exception.
      Yes, passing a non-POD class type object to "..." is Undefined Behavior.

      It's unclear why you're trying to copy the string to a fixed size buffer.



      when i debug strOut show as "*300".
      >
      does anyone know what the '*' represents at the beginning of the 300 ?
      Depends on your debugger if it's not part of the textual string value.


      does anyone know of a function that will return a unicode string from
      a long ?
      You stated above, "LongToStdWStri ng() is used elsewhere and works ok".


      so far i've tried stringstreams
      The wide string stream support in g++ for Windows is lacking; perhaps
      that's the compiler you're using?

      and _ltow
      Non-standard.

      but always get the * in front of the 300
      Mostly irrelevant.

      and wsprintf throws an exception ...
      If this is from the code shown above, then see above.

      --
      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?

      Comment

      • SteveB

        #4
        Re: wide string problem ...

        On 12 Mar, 09:59, "mimi" <cainiaodelixi. ..@gmail.comwro te:
        On Mar 12, 5:27 pm, "SteveB" <s...@thebretts .co.ukwrote:
        >
        >
        >
        Hi
        >
        I'm having major problems writing a function that converts a long
        value into a wide string !!! I'm more than likely going round in
        circles and not seeing the wood for the trees now but am frustreated
        just the same.
        >
        My function looks like this:
        >
        std::wstring CReportCreator: :SetEmpricalDef aults(const udtLONG&
        udtValue)
        {
        wstring ret = L"";
        ret = Utilities::Long ToStdWString(ud tValue.lngValue );
        return ret;
        >
        }
        >
        LongToStdWStrin g() is used elsewhere and works ok.
        >
        My call is this:
        >
        wstring strOut = SetEmpricalDefa ults(300L);
        >
        and then:
        >
        WCHAR xml[255];
        wsprintf(xml, L"<X><a=\"%s \" /></X>", strOut);
        >
        wsprintf(xml, L"<X><a=\"%s \" /></X>", strOut.data()); //Should be
        this?
        >
        >
        >
        >
        >
        wsprintf throws a scalar deleting desctructor exception.
        >
        when i debug strOut show as "*300".
        >
        does anyone know what the '*' represents at the beginning of the 300 ?
        >
        does anyone know of a function that will return a unicode string from
        a long ? so far i've tried stringstreams and _ltow but always get the
        * in front of the 300 and wsprintf throws an exception ...
        >
        many thanks- Hide quoted text -
        >
        - Show quoted text -- Hide quoted text -
        >
        - Show quoted text -
        many thanks

        Comment

        • SteveB

          #5
          Re: wide string problem ...

          Alf I'm sure you're a clever guy but I really just asked a question.
          The one line answer above was just fine.


          Comment

          • Alf P. Steinbach

            #6
            Re: wide string problem ...

            * SteveB:
            Alf I'm sure you're a clever guy but I really just asked a question.
            The one line answer above was just fine.
            Please quote relevant context.

            --
            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?

            Comment

            • Alf P. Steinbach

              #7
              Re: wide string problem ...

              * Alf P. Steinbach:
              * SteveB:
              >Alf I'm sure you're a clever guy but I really just asked a question.
              >The one line answer above was just fine.
              >
              Please quote relevant context.
              I mean, I'm not into guessing games: if you want help, be clear.

              --
              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?

              Comment

              • SteveB

                #8
                Re: wide string problem ...

                On 13 Mar, 14:08, "Alf P. Steinbach" <a...@start.now rote:
                * Alf P. Steinbach:
                >
                * SteveB:
                Alf I'm sure you're a clever guy but I really just asked a question.
                The one line answer above was just fine.
                >
                Please quote relevant context.
                >
                I mean, I'm not into guessing games: if you want help, be clear.
                >
                --
                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?
                i wasn't posting to get a lecture in how to phrase my questions alf.

                it was clear enough for someone else to aswer.

                i think you need to get over yourself.

                Comment

                • peter koch

                  #9
                  Re: wide string problem ...

                  On 16 Mar., 13:39, "SteveB" <s...@thebretts .co.ukwrote:
                  i think you need to get over yourself.
                  And I think you need to learn to behave yourself. Alf gave you lots of
                  valuable info. Being rude is about the silliest response imaginable.

                  /Peter

                  Comment

                  • SteveB

                    #10
                    Re: wide string problem ...

                    On 16 Mar, 13:08, "peter koch" <peter.koch.lar ...@gmail.comwr ote:
                    On 16 Mar., 13:39, "SteveB" <s...@thebretts .co.ukwrote:i think you need to get over yourself.
                    >
                    And I think you need to learn to behave yourself. Alf gave you lots of
                    valuable info. Being rude is about the silliest response imaginable.
                    >
                    /Peter
                    i wasn't being rude peter. mimi answered my question without needing
                    to dismantle the post and split hairs. my post was directed at the
                    community and was just at alf. if you read the reply he doesn't really
                    contribute anything at all. all i'm saying is that if he dopesn't know
                    the answer where is the benefit of his one hair splitters ? and the be
                    honest i did look at a few of alfs other posts before i commented.

                    Comment

                    • peter koch

                      #11
                      Re: wide string problem ...

                      On 16 Mar., 14:56, "SteveB" <s...@thebretts .co.ukwrote:
                      On 16 Mar, 13:08, "peter koch" <peter.koch.lar ...@gmail.comwr ote:
                      >
                      On 16 Mar., 13:39, "SteveB" <s...@thebretts .co.ukwrote:i think you need to get over yourself.
                      >
                      And I think you need to learn to behave yourself. Alf gave you lots of
                      valuable info. Being rude is about the silliest response imaginable.
                      >
                      /Peter
                      >
                      i wasn't being rude peter.
                      You think not? I doubt many would agree with you here.
                      mimi answered my question without needing
                      to dismantle the post and split hairs.
                      mimi gave you the wrong answer .data is not useful for the printf
                      family.
                      my post was directed at the
                      community and was just at alf. if you read the reply he doesn't really
                      contribute anything at all.
                      Alf guided you to allow you to make better code, he told you about a
                      possible compiler error, he told you about non-portability of your
                      code, he told you why your code does not work, and he did guide you to
                      find out about the "*" showing up in the debugger.
                      How can that not be useful?
                      all i'm saying is that if he dopesn't know
                      the answer where is the benefit of his one hair splitters ?
                      Hair splitters? There was no hairsplitting at all.
                      and the be
                      honest i did look at a few of alfs other posts before i commented.
                      If you had any intelligence, you'd then be aware that Alf answers are
                      knowledgeable and helpful. I can't remember ever seeing bad advice
                      from Alf, so if there is any it must be quite rare.
                      Now, I'd like to be able to put you in my killfile, but as I post via
                      google this is not an option.

                      /Peter

                      Comment

                      • Alf P. Steinbach

                        #12
                        Re: wide string problem ...

                        * SteveB:
                        On 13 Mar, 14:08, "Alf P. Steinbach" <a...@start.now rote:
                        >* Alf P. Steinbach:
                        >>
                        >>* SteveB:
                        >>>Alf I'm sure you're a clever guy but I really just asked a question.
                        >>>The one line answer above was just fine.
                        >>Please quote relevant context.
                        >I mean, I'm not into guessing games: if you want help, be clear.
                        >>
                        >--
                        >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?
                        >
                        i wasn't posting to get a lecture in how to phrase my questions alf.
                        >
                        it was clear enough for someone else to aswer.
                        >
                        i think you need to get over yourself.
                        Don't quote signatures, please.

                        Why are you trying to post negative drivel about me?

                        --
                        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?

                        Comment

                        • SteveB

                          #13
                          Re: wide string problem ...

                          Alf

                          I wasn't posting negative drivel about you - I appreciate that your
                          intentions were honourable and you wanted to guide me to making a
                          better choice - but not all people that post want this kind of advice
                          - i had a specific problem and i posted it on here to get a specific
                          answer. when i read your post it read as being condescending and not
                          very helpful. i was on a tight deadline and needed to make some
                          progress - i had tried google and other sources first. let's put this
                          to bed eh ?

                          Peter.
                          does anyone know what the '*' represents at the beginning of the 300 ?
                          Depends on your debugger if it's not part of the textual string value.

                          Read the post again Peter as Alf tells me very little.

                          Perhaps you could tell me why the .data() function is no good with
                          wsprintf ? I can't find anything on google or these groups that
                          mentions any problems and the code works ok ?

                          Belive me chaps I have no wish to fall out with anyone here - I find
                          these groups help me a lot. I had a gripe and now I've got it off my
                          chest.


                          Steve



                          Comment

                          • peter koch

                            #14
                            Re: wide string problem ...

                            On 16 Mar., 23:12, "SteveB" <s...@thebretts .co.ukwrote:
                            Alf
                            >
                            I wasn't posting negative drivel about you - I appreciate that your
                            intentions were honourable and you wanted to guide me to making a
                            better choice - but not all people that post want this kind of advice
                            - i had a specific problem and i posted it on here to get a specific
                            answer. when i read your post it read as being condescending and not
                            very helpful. i was on a tight deadline and needed to make some
                            progress - i had tried google and other sources first. let's put this
                            to bed eh ?
                            The questions and answers here are not just for you. They are also
                            meant as a source of information for others with similar problems.
                            >
                            Peter.
                            >
                            does anyone know what the '*' represents at the beginning of the 300 ?
                            >
                            Depends on your debugger if it's not part of the textual string value.
                            >
                            Read the post again Peter as Alf tells me very little.
                            On the contrary. Alf explains that you should check if the '*' is part
                            of the textual string. If it is not, you should consult your debugger
                            manual and find out why a '*' might be prepended. This last part is
                            off-topic in this group.
                            >
                            Perhaps you could tell me why the .data() function is no good with
                            wsprintf ? I can't find anything on google or these groups that
                            mentions any problems and the code works ok ?
                            Well - it is already there in the documentation of string::data and
                            the printf family. Read the documentation and you will have your
                            answer.

                            /Peter

                            /Peter

                            Comment

                            • SteveB

                              #15
                              Re: wide string problem ...

                              Peter
                              The questions and answers here are not just for you. They are also
                              meant as a source of information for others with similar problems.
                              >
                              see comment below.
                              does anyone know what the '*' represents at the beginning of the 300 ?
                              >
                              Depends on your debugger if it's not part of the textual string value.
                              >
                              Read the post again Peter as Alf tells me very little.
                              >
                              On the contrary. Alf explains that you should check if the '*' is part
                              of the textual string. If it is not, you should consult your debugger
                              manual and find out why a '*' might be prepended. This last part is
                              off-topic in this group.
                              >
                              Perhaps you could tell me why the .data() function is no good with
                              wsprintf ? I can't find anything on google or these groups that
                              mentions any problems and the code works ok ?
                              >
                              Well - it is already there in the documentation of string::data and
                              the printf family. Read the documentation and you will have your
                              answer.
                              >
                              In my original post I pointed out that I was converting long numbers
                              to wide strings and that was the problem. The '*' is not part of the
                              original string. How could it be ?

                              In reply to your final point I can find nothing on Google pointing to
                              problems with wstring::data and wsprintf. If I had the time to readl
                              all the documentation I really wouldn't have to post any questions on
                              here at all !

                              Please indulge me and explain the problem you claim to be so obvious.

                              Comment

                              Working...