Results 1 to 3 of 3

Thread: double concatenation with string

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    double concatenation with string

    I'm having trouble concatenating a string with a double. It should work fine but it doesn't:

    Code:
    temp_equ = ( temp_ans + temp_equ.substr( op_indices[counter]+1 ) );
    temp_equ is a string.. (a c++ string)

    temp_ans is a double.


    The weird thing is I created a test project and the following worked fine:
    Code:
    string s = 3.0 + "asdf";
    
    and
    
    double x = 3;
    string s = x + "asdf";
    Which is virtually what I'm trying to do.


    In my real project I tried the following to make sure it wasn't something to do with the substring:
    Code:
    temp_equ =  temp_ans + "asdf";
    and I still get the following exception:

    Code:
    67 C:\Dev-Cpp\Projects\Equation Parser\main.cpp invalid operands of types `double' and `const char[5]' to binary `operator+'
    What exactly am I doing wrong? It works in another file doing the exact same thing, but not in another...

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: double concatenation with string

    I don't think the string class' + operator is overloaded like that. You'll need to convert the double to a string in another way, using a stringstream, sscanf, boost::lexical_cast, etc...
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  3. #3

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: double concatenation with string

    Perfect. Thanks sunburnt.

Posting Permissions

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



Click Here to Expand Forum to Full Width