CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Posts
    31

    [RESOLVED] String manipulation

    I'm coming from a c# environment and I was wondering something instead of doing things on multiple lines...how to do it in one

    example: [C#]

    Code:
    string foo="LOL";
    string bar="zie lime";
    
    foo+=" at " +bar + " all the time";
    
    //output : "LOL at zie lime all the time"
    I've tried that with std::string and just gives me a bunch of errors saying essentially that the + doesn't belong there

    I was wondering if it's possible to do the same thing but in c++

    right now I'm doing
    [C++]
    Code:
    //lets say they are declared
    
    foo+=" at ";
    foo+=bar;
    foo+= "all the time";
    which makes the code really heavy

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: String manipulation

    It works fine so long as the leftmost expression is a std::string. In your case, it's not----" at " has type const char*. This is a legacy from C, mainly.

    You can solve it like so:
    Code:
    string foo="LOL";
    string bar="zie lime";
    
    foo+=string(" at ") +bar + " all the time";

  3. #3
    Join Date
    Jun 2009
    Posts
    31

    Re: String manipulation

    thanks works gr8

Tags for this Thread

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

Featured