Thread: How to add a string and an int?

  1. #1
    Terrancee
    Guest

    Question How to add a string and an int?

    Hi, I have a problem, and I can't find the answer.

    How do you add a string and an int, and push it into a vector.

    Code:
    int i = 5;
    vector<string> vs;
    vs.push_back(string("hello") + i);
    thanks

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    the integer itself has to be converted into a character array (string) and then you can add two together....

    look up the: itoa() function.........

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Use stringstreams
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed