double to String conversion, better way? - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20

Thread: double to String conversion, better way?

  1. #16
    Join Date
    Feb 2001
    Posts
    2,455
    So, now that I have the function Paul, what is the best way to use it? Start a GeneralFoo.h /GeneralFoo.cpp file and include into projects where I want to use it? Generate a GeneralFoo.dll? Create a CGeneralFoo class?

    Thanks for the starter code BTW.

    Mike B

  2. #17
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815
    Originally posted by Paul McKenzie
    It does...

    std::ostringstream::str() returns a std::string.
    I was referring to the uncorrected version which used
    Code:
    return strm.str;
    As Mike said, it compiled, but crashed.

  3. #18
    Join Date
    Apr 1999
    Posts
    27,446
    Originally posted by MikeB
    So, now that I have the function Paul, what is the best way to use it? Start a GeneralFoo.h /GeneralFoo.cpp file and include into projects where I want to use it?
    This is OK.
    Generate a GeneralFoo.dll?
    I wouldn't do this -- it is much simpler just to include the code in whatever module you want to use it in.
    Create a CGeneralFoo class?
    I would just stick to it being a standalone function.

    Regards,

    Paul McKenzie

  4. #19
    Join Date
    Apr 1999
    Posts
    27,446
    Originally posted by gstercken
    I was referring to the uncorrected version which used
    Code:
    return strm.str;
    As Mike said, it compiled, but crashed.
    It should never have compiled, regardless of whether the return type was std::string or not.

    From the Comeau compiler:
    Code:
    #include <sstream>
    #include <string>
    
    std::string foo()
    {
        std::ostringstream strm;
        return strm.str;    
    }
    
    using namespace std;
    int main()
    {
        std::string s = foo();
    }
    
    Compiler output:
    "ComeauTest.c", line 7: error: a pointer to a bound function may only be used to
              call the function
          return strm.str;    
                      ^
    
    1 error detected in the compilation of "ComeauTest.c".
    Regards,

    Paul McKenzie

  5. #20
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815
    Originally posted by Paul McKenzie
    It should never have compiled, regardless of whether the return type was std::string or not.
    Yea, you're right. A pointer to a nonstatic member function can't be returned. So this is yet another bug in the MS compiler.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center