问题
I have the following V8 code:
Local<String> getSumString(int32_t a, int32_t b){
int32_t sum = a + b;
return String::Concat(String::New("The sum is: ") , String::New(sum));
}
In the above function I want to add a
and b
, then want to return a string "The sum is: CALCULATED_SUM " .
I'm having problems in converting the calculated sum to a String so that it can be concatenated with other String.
回答1:
You don't say the nature of the error, but I'm guessing that the end of your output string is mangled, because you're instantiating a String from an int. V8 is interpreting that data as const char * data. You should instantiate an Integer from your int. Your last line will look like this instead:
return String::Concat(String::New("The sum is: ") , Integer::New(sum));
来源:https://stackoverflow.com/questions/22379918/how-to-convert-an-integer-to-a-string-in-v8