Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4574402
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:55:05+00:00 2026-05-21T19:55:05+00:00

Damage and Cost are integers, but as you can see in the code below

  • 0

Damage and Cost are integers, but as you can see in the code below I want to concatenate them with a string (if that’s the right word). How can I do this?

class Weapon : Shopable{
    private:
        int Damage;
    public:
        std::string getDesc() const{
            return getName()+"\t"+Damage+"\t"+Cost;
        }
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:55:06+00:00Added an answer on May 21, 2026 at 7:55 pm

    Provide yourself with this template:

    #include <sstream>
    
    template <class TYPE> std::string Str( const TYPE & t ) {
        std::ostringstream os;
        os << t;
        return os.str();
    }
    

    You can then say:

    return getName() + "\t" + Str( Damage ) + "\t" + Str(Cost);
    

    Note this is pretty much equivalent to Boost’s lexical_cast, and to similar facilities in the upcoming standard. Also note that this function trades performance for convenience and type-safety.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A friend sent me that code and alleges that it could damage the processor.
I am trying to observe if software can damage hardware today or not.For that
I can't quite figure out the right pattern to use with PHP's preg_replace function.
I know that the C# Random class does not make true random numbers, but
I'm currently building the damage mechanic for my game. Two classes handle this, the
Here's my XML file: <?xml version=1.0 encoding=utf-8 ?> <Hero> <Legion> <Andromeda> <HeroType>Agility</HeroType> <Damage>39-53</Damage> <Armor>3.1</Armor>
I'm developing a game. I want to have game entities each have their own
Recently a client was concerned that their SWF was insecure because the XML path
I need a query to prevent a join that produces 1.34218E+35 results! I have
Why can't java gracefully return some value with a division by zero and instead

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.