Thread: help a newbie :(

  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,708
    Code:
    char * l_strcat( char str[], long my_long) {
      char temp[MAX];
      sprintf(temp, " %Li ", my_long);
      return strcat(str, temp);
     }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  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, 07:49 PM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  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