help a newbie :(

This is a discussion on help a newbie :( within the C++ Programming forums, part of the General Programming Boards category; I'm just starting C++, and I need help with a something.... How can I concatenate numerical data (integers/longs) to string ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    18

    help a newbie :(

    I'm just starting C++, and I need help with a something....
    How can I concatenate numerical data (integers/longs) to string values??
    I've tried some things but nothing works..

    Thanks in advance for any help..
    ~void

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,670
    Code:
    char * l_strcat( char str[], long my_long) {
      char temp[MAX];
      sprintf(temp, " %Li ", my_long);
      return strcat(str, temp);
     }



    ITSA
    Socket Library!

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    I'll try then:

    Code:
    template<typename T>
    void mystrcat(std::string& str, T t)
    {
      std::stringstream sout;
      sout << str << t;
      str = sout.str();
    }
    
    int main()
    {
      using namespace std;
      string p = "Sang-drax";
      mystrcat(p,123);
      cout << p;
    }
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 06:49 PM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 11:53 AM
  3. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 01:17 PM
  4. Some help for a newbie?
    By Ilmater in forum C++ Programming
    Replies: 23
    Last Post: 04-19-2004, 07:44 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21