Results 1 to 3 of 3

Thread: Question about returning variables and text

  1. #1

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772

    Question about returning variables and text

    Hi,

    I am trying to return a variable in a string, like this:

    Code:
    void toString()
    {
         return "The variable is" +variable1;
    }
    I didn't think this would work, and it didn't, so how can i do this? I don't want to do it with cout instead of return.
    Alcohol & calculus don't mix.
    Never drink & derive.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Use the string class:
    Code:
    #include <string>
    
    using namespace std;
    
    string toString() {
        return "The variable is: " + sVar;
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    K, thanks, and i just realized i put this in chit chat, not C++, sorry everyone.
    Alcohol & calculus don't mix.
    Never drink & derive.

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